找到你要的答案

Q:Converting Indices of Series to Columns

Q:系列换算指标

I need to convert the Indices of a Series amounts into its Columns. For example, I need to convert:

     1983-05-15      1
     1983-11-15      1
     1984-05-15      1
     1984-11-15     101

into:

     1983-05-15      1983-11-15      1984-05-15      1984-11-15
             1               1               1              101

I wasn't able to find any documentation on doing this for Series type Objects specifically and don't know how to do this.

Thank You

我需要把级数的指数转换成列。例如,我需要转换:

     1983-05-15      1
     1983-11-15      1
     1984-05-15      1
     1984-11-15     101

成:

     1983-05-15      1983-11-15      1984-05-15      1984-11-15
             1               1               1              101

我不能找到任何文件,这样做的系列类型的对象,特别是不知道如何做到这一点。

谢谢您

answer1: 回答1:

Build a DataFrame out of your Series, then the .T property returns a transposed version.

In [87]: pd.DataFrame(s).T
Out[87]: 
   1983-05-15  1983-11-15  1984-05-15  1984-11-15
0           1           1           1         101

建立一个数据框出你的系列,然后T属性返回一个转置的版本。

In [87]: pd.DataFrame(s).T
Out[87]: 
   1983-05-15  1983-11-15  1984-05-15  1984-11-15
0           1           1           1         101
answer2: 回答2:

There is a built in method to convert a series to a dataframe, to_frame:

In [146]:    
s.to_frame().T

Out[146]:
1983-05-15  1983-11-15  1984-05-15  1984-11-15
1                    1           1         101

有一个内置的方法将一系列的一个数据框,to_frame:

In [146]:    
s.to_frame().T

Out[146]:
1983-05-15  1983-11-15  1984-05-15  1984-11-15
1                    1           1         101
python  pandas