Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将pd.Series转换为索引为日期、列为时间的pd.DataFrame?_Python_Pandas - Fatal编程技术网

Python 如何将pd.Series转换为索引为日期、列为时间的pd.DataFrame?

Python 如何将pd.Series转换为索引为日期、列为时间的pd.DataFrame?,python,pandas,Python,Pandas,我有一个pd.Series,它的索引是pd.DataTimeIndex。我想将1D系列转换为一个数据框架,其索引是每个数据的日期,列是每个数据的时间。大概是这样的: 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

我有一个pd.Series,它的索引是pd.DataTimeIndex。我想将1D系列转换为一个数据框架,其索引是每个数据的日期,列是每个数据的时间。大概是这样的:

            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
让我们做吧

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

或者不修改s:s.set_index[s.index.date,s.index.time].unstack?你试过什么,做过什么研究吗?请看。