Install Python Package in Anaconda

The following command can be used to install a Python package in Anaconda: Copy pip install package_name Steps to Install a Python Package in Anaconda Step 1: Open the Anaconda Prompt Locate your Anaconda Prompt. For example, if you’re using Windows, you can simply type ‘Anaconda Prompt‘ in the Windows Search Bar (and then click … Read more

How to Create While Loop in Python

To create a while loop in Python: Copy while condition is true: perform an action 4 Examples of While Loop in Python Example 1: Create a Countdown To start, create a countdown, where: Based on the above rules, the condition for the countdown is therefore:  countdown > 3 And so long as this condition is true, … Read more

How to Convert Pandas DataFrame into a List

You can convert Pandas DataFrame into a list in Python using tolist(): Copy df.values.tolist() In this short guide, you’ll see an example of converting Pandas DataFrame into a list. Example of Converting Pandas DataFrame into a List Let’s say that you have the following data about products and prices: product price Tablet 250 Printer 100 … Read more

Export Matplotlib Charts to a PDF

In this short guide, you’ll see how to export Matplotlib charts to a PDF file. More specifically, you’ll observe how to export scatter and line charts into a PDF file. The Dataset used for the Scatter Chart Let’s say that you want to display the relationship between two variables: You may then use a scatter … Read more

Concatenate Column Values in Pandas DataFrame

Here are 2 ways to concatenate column values in Pandas DataFrame: (1) For strings only: Copy df[“new_column_name”] = df[“1st_column_name”] + df[“2nd_column_name”] + … (2) For a mix of strings and integers (or just integers): Copy df[“new_column_name”] = df[“1st_column_name”].map(str) + df[“2nd_column_name”].map(str) + … Examples Example 1: Concatenating values under a single DataFrame Assume that you have … Read more

Place Matplotlib Charts on a Tkinter GUI

In this short guide, you’ll see the steps to place matplotlib charts on a tkinter GUI. More specifically, you’ll learn how to embed the following charts on your GUI: Steps to place matplotlib charts on a tkinter GUI Step 1: Prepare the datasets for the charts Firstly, you’ll need to prepare the datasets for the charts. … Read more

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