Reputation: 1033
I'm trying to append a 3x2 numpy array to an existing dataframe. Something like this:
import pandas as pd
import numpy as np
df = pd.Dataframe({"A": [0,0,0], "B": [1,1,1]})
arr = np.arange(6).reshape(3, 2)
df[["C", "D"]] = arr # NOPE!
How do I get this to work?
Upvotes: 1
Views: 5749
Reputation: 601
It didn't work because you need to pass a df:
arr = pd.DataFrame(np.arange(6).reshape(3, 2))
df[["C", "D"]] = arr #YEP
#Output
A B C D
0 0 1 0 1
1 0 1 2 3
2 0 1 4 5
Upvotes: 0