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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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