How to Install Python on Windows 11

In this short guide, you’ll see how to install Python on Windows 11 from scratch. You’ll also learn how to run a simple script in Python. Steps to Install Python on Windows 11 Step 1: Download Python To start, go to python.org/downloads and then click on the button to download the latest version of Python. … Read more

How to Create a Batch File Directly from Python

In this short guide, you’ll see how to create a batch file directly from Python. To begin, here is a template that you can use to create your batch file from Python: Copy my_bat = open(r’Path to store the new batch file\File name.bat’, ‘w+’) my_bat.write(‘command to be included in the batch file’) my_bat.close() Steps to … Read more

Convert Images to PDF using Python

In this short guide, you’ll see how to convert images to PDF using Python. The PIL package will be used to accomplish this goal. To begin, here is a template that you may use to convert a png image to PDF using Python (for JPEG, use the file extension of ‘jpg’): Copy from PIL import … Read more

Convert a Dictionary to Pandas DataFrame

You may use the following template to convert a dictionary to Pandas DataFrame: Copy import pandas as pd my_dict = {‘key_1’: ‘value_1’, ‘key_2’: ‘value_2’, …} df = pd.DataFrame(list(my_dict.items()), columns=[‘column_1’, ‘column_2’]) print(df) Steps to Convert a Dictionary to Pandas DataFrame Step 1: Gather the Data for the Dictionary To start, gather the data for your dictionary. … Read more

Average each Column and Row in Pandas DataFrame

To get the average of each numeric column and row in Pandas DataFrame (apply only for numeric values): Average each column: Copy df.mean(axis=0) Average each row: Copy df.mean(axis=1) Steps to get the Average of each Column and Row in Pandas DataFrame Step 1: Prepare the data For example, here is a simple dataset that contains … Read more

Create a Pie Chart in Python using Matplotlib

To create a pie chart in Python using Matplotlib: Copy import matplotlib.pyplot as plt my_data = [value1, value2, value3, …] my_labels = [“label1”, “label2”, “label3″, …] plt.pie(my_data, labels=my_labels, autopct=”%1.1f%%”) plt.title(“My Title”) plt.axis(“equal”) plt.show() Steps to Create a Pie Chart in Python using Matplotlib Step 1: Install the Matplotlib package Install the Matplotlib package if you … Read more

Convert Integers to Floats in Pandas DataFrame

Two approaches to convert integers to floats in Pandas DataFrame: (1) The astype(float) approach: Copy df[‘DataFrame Column’] = df[‘DataFrame Column’].astype(float) (2) The apply(float) approach: Copy df[‘DataFrame Column’] = df[‘DataFrame Column’].apply(float) Steps to Convert Integers to Floats in Pandas DataFrame Step 1: Create a DataFrame To start, create a DataFrame that contains integers. For example, let’s … Read more

Convert CSV to Excel using Python

To convert a CSV file to an Excel file using Python: Copy import pandas as pd read_file = pd.read_csv(r”Path where the CSV file is stored\File name.csv”) read_file.to_excel(r”Path to store the Excel file\File name.xlsx”, index=False, header=True) Steps to Convert a CSV to Excel using Python Step 1: Install the Pandas package If you haven’t already done … Read more

How to Take a Screenshot using Python

You may use the following template to take a screenshot using Python: Copy import pyautoguimy_screenshot = pyautogui.screenshot()my_screenshot.save(r”Path to save screenshot\file name.png”) Steps to Take a Screenshot using Python Step 1: Install the pyautogui package To start, install the pyautogui package using this command: Copy pip install pyautogui You may check the following guide for the … Read more