Export Pandas DataFrame to an Excel File

You can export Pandas DataFrame to an Excel file using to_excel: Copy df.to_excel(r”Path to store the Excel\File Name.xlsx”, index=False) And if you want to export your DataFrame to a specific Excel Sheet: Copy df.to_excel(r”Path to store the Excel\File Name.xlsx”, sheet_name=”Your sheet name”, index=False) Note: you’ll have to install openpyxl if you get the following error: ModuleNotFoundError: … Read more

Get the Current Date in Python

In this short guide, you’ll see how to get the current date in Python using the datetime module. More specifically, you’ll observe how to get: Get the Non-Formatted Current Date in Python For the first case, simply apply the following syntax to get the current date in Python: Copy import datetimecurrent_date = datetime.datetime.today()print(“Current Date: ” … Read more

5 ways to apply an IF condition in Pandas DataFrame

In this guide, you’ll see 5 different ways to apply an IF condition in Pandas DataFrame. Specifically, you’ll see how to apply an IF condition for: Applying an IF condition in Pandas DataFrame Let’s now review the following 5 cases: (1) IF condition – Set of numbers Suppose that you created a DataFrame in Python … Read more

Create Scatter, Line and Bar Charts using Matplotlib

To create scatter plots, line charts, and bar charts using Matplotlib: Scatter plot Copy import matplotlib.pyplot as pltx_axis = [“value_1”, “value_2”, “value_3”, …]y_axis = [“value_1”, “value_2”, “value_3”, …]plt.scatter(x_axis, y_axis)plt.title(“title name”)plt.xlabel(“x_axis name”)plt.ylabel(“y_axis name”)plt.show() Line chart Copy import matplotlib.pyplot as pltx_axis = [“value_1”, “value_2”, “value_3”, …]y_axis = [“value_1”, “value_2”, “value_3”, …]plt.plot(x_axis, y_axis)plt.title(“title name”)plt.xlabel(“x_axis name”)plt.ylabel(“y_axis name”)plt.show() Bar chart … Read more

Uninstall a Package in Python using PIP

In this short guide, you’ll see how to uninstall a package in Python using PIP. If you’re using Windows, you’ll be able to uninstall a Python package by opening the Windows Command Prompt, and then typing this command: Copy pip uninstall package_name Note: the above method would only work if you already added Python to … Read more

How to Create Pandas DataFrame in Python

In this short guide, you’ll see two different methods to create Pandas DataFrame: Method 1: typing the values in Python to create Pandas DataFrame To create Pandas DataFrame in Python, you can follow this generic template: Copy import pandas as pd data = {‘first_column’: [‘first_value’, ‘second_value’, …],         ‘second_column’: [‘first_value’, ‘second_value’, …], … Read more

How to Export Pandas DataFrame to a CSV File

In order to export Pandas DataFrame to a CSV file in Python: Copy df.to_csv(r”Path to store the exported CSV file\File Name.csv”, index=False) And if you wish to include the index, then simply remove “, index=False” from the code: Copy df.to_csv(r”Path to store the exported CSV file\File Name.csv”) Steps to Export Pandas DataFrame to a CSV … Read more

How to Run a Batch File from Python

In this short guide, you’ll see the steps to run a batch file from Python. To start, here is a simple template that you can use to run a batch file directly from Python: Copy import subprocess subprocess.run([r”path where the batch file is stored\file_name.bat”]) Steps to Run a Batch File from Python Step 1: Create … Read more

Delete a File or Folder Using Python

In this short guide, you’ll see how to delete a file or folder using Python. In particular, you’ll see how to: To start, here is the general syntax to delete a file or folder: Delete a file Copy import os os.remove(r”Path where the file is stored\File Name.File type”) Delete an empty folder Copy import os … Read more