Categories
Python Answers

How to add a new column to an existing Python Pandas DataFrame?

Spread the love

To add a new column to an existing Python Pandas DataFram, we can the assign method.

For instance, we write

df1 = df1.assign(e=pd.Series(np.random.randn(sLength)).values)

to call assign on the df1 data frame.

We add values to it by setting e to pd.Series(np.random.randn(sLength)).values.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.