Add empty column to DataFrame pandas

In this post, we will see how to add empty column to DataFrame pandas.

There are multiple ways to add empty column to DataFrame.

Using assignment

You can use assignment to create new columns in python.

Output:

Using reindex() method

You can use DataFrame.reindex() method to create new columns in python.

Output:

If Pandas version is greater than 0.20.0, you can change highlighted line as below:

Using insert() method

You can use DataFrame.insert() method to create new columns in python. You can use insert() method to add column at any index.
Here is signature of insert() method.

To insert Gender column at first index, you can use:

Output:

Conclusion

If you just need add empty single column, you can use assignment or insert() method. reindex() method is very convienient in case you need to add multiple empty columns.

That’s all about how to add empty column to DataFrame pandas

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *