How to List All the Packages Installed in Python

Here are 2 ways to list all the packages installed in Python: (1) Run ‘pip list‘ in the command prompt or terminal: Copy pip list Note that this command would only work if you already added Python to the Path. To save this list to a text file: Copy pip freeze > installed_packages.txt (2) Run … Read more

Generate Random Integers in Pandas Dataframe

In this short guide, you’ll see how to generate random integers in Pandas DataFrame under: You’ll also see how to convert those integers to different data types, such as floats or strings. Generate Random Integers under a Single DataFrame Column Here is a template that you may use to generate random integers under a single … Read more

How to Create a Time Delay in Python

You may use the time module in order to create a time delay in Python: Copy import time time.sleep(number of seconds of delay) Here are few examples of time delays: 3 seconds time delay: Copy import time time.sleep(3) 3 minutes time delay: Copy import time time.sleep(3 * 60) 3 hours time delay: Copy import time … Read more

How to Create a Progress Bar in Python

In this short guide, you’ll see how to create a progress bar in Python using the tqdm package. You’ll also observe how to add a GUI to track your progress. Steps to Create a Progress Bar in Python Step 1: Install the tqdm package To begin, install the tqdm package using this command: Copy pip … Read more

How to apply an input() function in Python

To apply an input function in Python: Copy value = input() Next, you’ll see 3 examples of an input function: 3 Examples of an Input Function in Python Example 1: input function for a text/string You can utilize an input function in order to gather text from users. For example, the following syntax can be … Read more

Convert Text File to CSV using Python

To convert a text file to a CSV file using Python: Copy import pandas as pd read_file = pd.read_csv(r”Path where the Text file is stored\File name.txt”) read_file.to_csv(r”Path where the CSV will be saved\File name.csv”, index=False) Steps to Convert a Text File to CSV using Python Step 1: Install the Pandas package If you haven’t already … Read more

Convert CSV to JSON using Python

To convert a CSV file to a JSON file using Python: Copy import pandas as pddf = pd.read_csv(r”Path where the CSV file is saved\File Name.csv”)df.to_json(r”Path where the new JSON file will be stored\New File Name.json”) Steps to Convert CSV to JSON using Python Step 1: Prepare the CSV File To start, prepare a CSV file … Read more

How to Move a File or Directory in Python

To move a file in Python: Copy import shutil original = r”original path of the file\file_name.file_extension” target = r”target path to store the file\file_name.file_extension” shutil.move(original, target) Steps to Move a File in Python Step 1: Capture the Original Path To begin, capture the original path where your file is currently stored. For example, let’s suppose … Read more

Convert PNG to JPG using Python

To convert PNG to JPG using Python: Copy from PIL import Imageim = Image.open(r”path where the PNG is stored\file name.png”)im.save(r”path where the JPG will be stored\new file name.jpg”) Steps to Convert PNG to JPG using Python Step 1: Install the PIL package You can install the PIL package using the command below: Copy pip install … Read more

How to Sort a List in Python

To sort a List in Python in an ascending order: Copy my_list.sort() To sort a List in a descending order: Copy my_list.sort(reverse=True) 4 Cases of Sorting a List Case 1: Sort a List in an Ascending Order To start, create a List of names: Copy names = [“Jon”, “Maria”, “Bill”, “Liam”, “Emma”]print(names) The resulted List: … Read more