How to lowercase Pandas DataFrame column names and values?

As part of your data preparation process you might need to drop one ore multiple redundant columns, calculate new column values or simply manipulate column names or values. In this tutorial we’ll learn how to convert columns names and values to lowercase. Creating example data Let’s assume that we have this very simple example DataFrame. … Read more

How to find the max of two or more columns in Pandas?

There might be cases in which you’ll need to perform calculations across several columns in your Pandas DataFrame. In this post we’ll learn how to easily use the max() DataFrame to retrieve the maximum value across two or more Pandas column. Example DataFrame We’ll get started with a very simple DataFrame that you can use … Read more

How to replace nan values with a string in Pandas?

Today we’ll learn how to replace empty values in Pandas DataFrame columns with a string object. We’ll show how to use the Pandas DataFrame replace() method to easily convert We’ll start by defining a sample DataFrame that you can use in order to follow along this example: Let’s look into our DataFrame: month office salary … Read more

How to convert Pandas timestamps to datetime objects?

Today we’ll learn how to convert timestamps to Python datetime objects. In Pandas we use those terms almost interchangeably though, which renders this a bit confusing. Creating Pandas timestamps We can easily create timestamps using the Pandas pd.TimeStamp function. Here is a very simple example to get us started with the tutorial: This will return … Read more

How to filter rows by multiple conditions in Pandas?

In today’s tutorial we’ll learn how to select DataFrame rows by specific or multiple conditions. For people new to Pandas but experienced in SQL, we’ll learn how to write where statements aimed at selecting data from our DataFrames. We’ll look into several cases: Filtering rows by column value Selecting by multiple boolean conditions Selecting only … Read more

How to check if a Pandas column contains a string?

In this Data Analysis tutorial we’ll learn how to use Python to search for a specific or multiple strings in a Pandas DataFrame column. In a nutshell we can easily check whether a string is contained in a column using the .str.contains() Series function: df_name[‘col_name’].str.contains(‘string’).sum() Read on for several examples of using this capability. Creating … Read more

How to create Pandas date range objects?

In this tutorial we’ll learn lots of very useful information about using the Pandas data range objects. We’ll learn about two very versatile Pandas functions: data_range and bdate_range that allow to create data ranges with ease. This will come very handy when pre-process / wrangling your data before analysis and visualization. Preparation Before starting to … Read more