How to export a Python Dataframe column to a list?

This quick tutorial will cover the topic of writing a DataFrame column to a Python list. Consider the following code snippet: Here’s our DataFrame header: manager target 0 Debbie 32000 1 Daisy 45000 2 Dorothy 18000 3 Tim 20000 4 Debbie 32000 Using pd.DataFrame.tolist() to write column to a list Here’s the Python code you’ll … Read more

Add Python lists as columns in Pandas DataFrames

Our quick data wrangling recipe today covers the topic of adding Python lists to Pandas DataFrames as columns and rows. Creating the data We’ll start with a simple dataset that we’ll use throughout this tutorial examples. Go ahead and copy this code into your data analysis Python environment. Let’s also define a simple list for … Read more

How to count unique values in a Pandas Groupby object?

Today’s Python data wrangling recipe is about counting number of non unique entries in a Pandas DataFrame groupby object. We’ll start by importing the Pandas library and then acquiring our dataset from a comma separated value file into a DataFrame. We’ll use the Pandas read_csv function: Let’s take a quick look at the DataFrame Header: … Read more

How to replace values in Pandas series?

In today’s recipe i would like to expand on different methods for replacing values in a Pandas series. In this tutorial we’ll do extensive usage of the Series replace method, that will prove very useful to quickly manipulate our data. Replacing data in a Python series We’ll touch on several cases: Change Series values Replacing … Read more

How to delete columns from your Pandas dataframe?

Yesterday we learnt about how we can easily delete rows from a dataframe based on specific conditions, and today, we’ll focus on a similar process just for columns. In this post we’ll show how to handle a few scenarios: Removing one columns based on labels Deleting multiple columns based on labels Dropping columns base on … Read more