[英]How to convert a pd.Series to a pd.DataFrame where indices are dates and columns are time?
I have pd.Series whose index are pd.DataTimeIndex.我有索引为 pd.DataTimeIndex 的 pd.Series。 I would like to convert the 1D series to a DataFrame whose indices are the dates and columns are time of each data.
我想将一维系列转换为 DataFrame,其索引是日期,列是每个数据的时间。 Something like this:
像这样的东西:
08:01:00 08:02:00 08:03:00 08:04:00 08:05:00
2011-04-04 2.50 2.65 2.65 2.7 2.8
2011-04-05 -4.30 -4.45 -4.70 -4.6 -5.0
2011-04-06 25.75 26.30 26.50 26.7 27.1
2011-04-07 1.15 -0.45 -0.45 -0.4 0.2
Let us do让我们做
s.index=pd.MultiIndex.from_arrays([s.index.date,s.index.time])
df=s.unstack()
df
08:01:00 08:02:00 08:03:00 08:04:00 08:05:00
2011-04-04 2.50 2.65 2.65 2.7 2.8
2011-04-05 -4.30 -4.45 -4.70 -4.6 -5.0
2011-04-06 25.75 26.30 26.50 26.7 27.1
2011-04-07 1.15 -0.45 -0.45 -0.4 0.2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.