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'
cc = pd.Series(np.zeros(len(A)*20))
ac = pd.Series(np.random.randn(10))
I try this but I had an empty dataframe
index = pd.date_range(start=pd.datetime(2017, 1,1), end=pd.datetime(2017, 1, 2), freq='1h')
df = pd.DataFrame(index=index)
df = df.join(pd.concat([pd.DataFrame(cc).T] * len(df), ignore_index=True))
df = df.join(pd.concat([pd.DataFrame(ac).T] * len(df), ignore_index=True))
The final result should be something like this :
cc ac
2017-01-01 00:00:00 1 0.247043
2017-01-01 01:00:00 1 -0.324868
2017-01-01 02:00:00 1 -0.004868
2017-01-01 03:00:00 1 0.047043
2017-01-01 04:00:00 1 -0.447043
2017-01-01 05:00:00 NaN NaN
... ... ...
It's not a problem if we always have NaN in the final result.
EDIT:
After the answer of @piRSquared , i have to add a loop but i got an error in the keys :
az = [cc, ac]
for i in az:
df.join(
pd.concat(
[pd.Series(s.values, index[:len(s)]) for s in [i]],
axis=1, keys=[i]
)
)
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().