How to Add an Empty Column to a Pandas Dataframe?

Spread the love

Problem –

You want to add an empty column to a pandas dataframe.

Solution –

Let’s read a dataset to illustrate.

import pandas as pd
import numpy as np

url = ''
df = pd.read_csv(url)

Now, let’s say I want to add an empty column location to this dataframe. To do that I will just create a new column and fill it with np.nan.

df['location'] = np.nan

Rating: 1 out of 5.

Leave a Reply