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

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.