How to add Python to Windows PATH

There are few ways to add Python to Windows PATH. In this short guide, you’ll see two methods to add Python to Windows path: Method 1: Install a Recent Version of Python You can easily add Python to Windows path by downloading a recent version of Python, and then checking the box to Add Python … Read more

Create Pivot Table in Python using Pandas

In this short guide, you’ll see how to create a pivot table in Python using Pandas. The Example Imagine that you have the following DataFrame that contains data about sales across 4 quarters: Copy import pandas as pddata = {‘person’: [‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘A’, ‘B’, ‘C’, ‘D’, ‘E’, … Read more

IF, ELIF and ELSE in Python (with Examples)

Here is a template that you may reference when performing IF, ELIF and ELSE in Python: Copy if condition_1: perform an action if condition_1 is metelif condition_2: perform an action if condition_2 is metelse: perform an action if neither condition_1 nor condition_2 is met Next, you’ll see the following 4 examples: Example 1: IF and … Read more

Schedule Python Script using the Windows Scheduler

In this guide, you’ll see the steps to schedule a Python script using the Windows Scheduler. The Steps Step-1: Prepare the Python Script For example, let’s suppose that the goal is to display ‘Hello World‘ each day at 6am. Here is the Python script to be used for our example (you may use another Python script … Read more

How to Sort Pandas DataFrame (with examples)

You may use df.sort_values in order to sort Pandas DataFrame. In this short guide, you’ll see 4 examples of sorting: To start with a simple example, let’s say that you have the following data about cars: Brand Price Year HH 22000 2015 TT 25000 2013 FF 27000 2018 AA 35000 2018 You can then capture that … Read more

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