PV8
PV8

Reputation: 6260

Add array to a dataframe in python

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.

Upvotes: 2

Views: 73

Answers (1)

jezrael
jezrael

Reputation: 862691

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

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

Upvotes: 2

Related Questions