Pandas: How to count number of elements after aggregating with groupby.

In Data Analysis we often aggregate our data and then typically apply specific functions on it. Today we’ll learn how to count values on data that we have previously aggregated using the DataFrame.groupby() Pandas method. Creating example data Let’s first import the Python Pandas library and acquire data into our Python development environment: Groupby and … Read more

Find index of Pandas row values in Python dataframe columns

In today’s tutorial we’ll learn how to easily find the index values of specific rows in Pandas DataFrames which answer specific condition. We’ll be looking at Preparations We’ll start by importing Pandas and Numpy, then we’ll go ahead and create some example data. Here’s our DataFrame Find index of specific column value The result will … Read more

How to read one or multiple text files into a Pandas DataFrame?

When data wrangling with Pandas you’ll eventually work with multiple types of data sources. In today’s tutorial, we will learn how use Pyhton3 to import text (.txt) files into a Pandas DataFrames. The process as expected is relatively simple to follow. Example: Reading one text file to a DataFrame in Python Suppose that you have … Read more

How to multiply two or more columns in Python DataFrames?

In Data Analysis we often execute arithmetic operations on our dataset. In today’s tutorial we would like to show how you can easily multiply two or more columns in a single DataFrame or on multiple ones. Multiply Pandas DataFrame columns In order to create a new column that contains the product of two or more … Read more

How to filter a DataFrame by column and row values?

In today’s Data Wrangling tutorial we’ll learn how to use Python in order to subset Pandas DataFrames and select specific columns according to column data and label values. This is useful for many different cases: Cleaning up data by filtering missing or invalid data, Visualizing only subsets of the data, prepare data for export to … Read more

Find standard deviation of Pandas DataFrame columns , rows and Series

In today’s tutorial we will learn how to calculate the standard deviation of a Pandas DataFrame. We’ll calculate the standard deviation for several cases: Example DataFrame We’ll start by importing the Pandas library and reading a csv file with our data into a new DataFrame. Here’s the DataFrame: Calculate std deviation of a Pandas Series … Read more

How to remove the first column of a Pandas DataFrame?

In today’s tutorial we’ll learn how use Python in order to remove the first column of a Pandas DataFrame. Let’s assume, that we have a DataFrame that has a couple of columns as well as a sequential index: Here’s the DataFrame that we have just created: Removing the index column If we want to get … Read more

How to count unique and specific values in Pandas DataFrames?

As part of your Data wrangling process you might need to quickly count occurrences of same or different values in your entire dataset or in specific columns. In today’s tutorial we’ll go over several use cases and provide some short example code snippets to help you tackle each scenario. Preparations We’ll first acquire our dataset … Read more