I have a DataFrame and a Series of different dimensions
from pandas import *
df = DataFrame({'a':[1,2,3],'b':[1,2,3]})
s = Series([1,2,3,4,5])
is there a way to insert s into df without creating a reindexed copy of df first? Currently i am using
df = df.reindex(range(len(s))
df['s'] = s
print df
a b s
0 1 1 1
1 2 2 2
2 3 3 3
3 NaN NaN 4
4 NaN NaN 5
Use concat:
In [19]:
concat([df,s], axis=1)
Out[19]:
0 1 2
0 1 1 1
1 2 2 2
2 3 3 3
3 NaN NaN 4
4 NaN NaN 5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With