Add array to a dataframe in python

PV8 :

I have a datframe df, with the df.shape: (971,1)

And I have an array with the anarray.shape: (971,80).

How can I add the array to my dataframe, so that I have the shape: (971,81).

I only find solutions where the array goes into one column, but in my case it should go into several columns.

jezrael :

I believe you need helper DataFrame with same index like df and then DataFrame.join:

df = df.join(pd.DataFrame(anarray, index=df.index))

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=12573&siteId=1