Append Two Pandas Series To A Dataframe By Columns
I have a dataframe and two Pandas Series ac and cc, i want to append this two series as column. But the problem is that my dataframe has a time index and Series as integer A='a' c
Solution 1:
df.join(
pd.concat(
[pd.Series(s.values, index[:len(s)]) for s in [cc, ac]],
axis=1, keys=['cc', 'ac']
)
)
cc ac
2017-01-01 00:00:00 0.0 -0.319653
2017-01-01 01:00:00 0.0 0.630061
2017-01-01 02:00:00 0.0 -1.648402
2017-01-01 03:00:00 0.0 -1.141017
2017-01-01 04:00:00 0.0 -0.643353
2017-01-01 05:00:00 0.0 0.718771
2017-01-01 06:00:00 0.0 0.379173
2017-01-01 07:00:00 0.0 1.799804
2017-01-01 08:00:00 0.0 0.883260
2017-01-01 09:00:00 0.0 0.788289
2017-01-01 10:00:00 0.0 NaN
2017-01-01 11:00:00 0.0 NaN
2017-01-01 12:00:00 0.0 NaN
2017-01-01 13:00:00 0.0 NaN
2017-01-01 14:00:00 0.0 NaN
2017-01-01 15:00:00 0.0 NaN
2017-01-01 16:00:00 0.0 NaN
2017-01-01 17:00:00 0.0 NaN
2017-01-01 18:00:00 0.0 NaN
2017-01-01 19:00:00 0.0 NaN
2017-01-01 20:00:00 NaN NaN
2017-01-01 21:00:00 NaN NaN
2017-01-01 22:00:00 NaN NaN
2017-01-01 23:00:00 NaN NaN
2017-01-02 00:00:00 NaN NaN
Post a Comment for "Append Two Pandas Series To A Dataframe By Columns"