繁体   English   中英

如何将循环时间序列pandas数据框转换为pandas多索引数据框

[英]How to transform recurrent time series pandas data frame to pandas multi-index data frame

是否有 Pandas 函数将下面表示的数据框转换为多索引时间序列数据框?

    ticker  date    lastupdated ev  evebit  evebitda    marketcap   pb  pe  ps
None                                        
0   XOM  2018-12-31 2018-12-31  323071.3    12.3    7.1  288703.3   1.5 12.4    1.1
1   XOM  2018-12-28 2018-12-28  322986.6    12.3    7.1  288618.6   1.5 12.4    1.1
2   XOM  2018-12-27 2018-12-27  326246.7    12.5    7.1  291878.7   1.5 12.6    1.1
3   XOM  2018-12-26 2018-12-26  324976.5    12.4    7.1  290608.5   1.5 12.5    1.1
4   XOM  2018-12-24 2018-12-24  311724.7    11.9    6.8  277356.7   1.5 11.9    1.0
5   AAPL 2018-12-31 2018-10-21  1137146.7   16.2    14.0 1054517.7  9.2 18.8    4.1
6   AAPL 2018-12-28 2018-10-21  1151491.6   16.4    14.2 1068862.6  9.3 19.0    4.2
7   AAPL 2018-12-27 2018-10-21  1160185.5   16.5    14.3 1077556.5  9.4 19.2    4.2
8   AAPL 2018-12-26 2018-10-21  1178394.3   16.7    14.5 1095765.3  9.5 19.5    4.3
9   AAPL 2018-12-24 2018-10-21  1185590.9   16.8    14.6 1102961.9  9.6 19.7    4.3

获得以下带有重新分组日期的数据框:

                 lastupdated    ev  evebit  evebitda    marketcap   pb  pe  ps
date      ticker                                            
2018-12-31 XOM    2018-12-31    323071.3    12.3    7.1  288703.3   1.5 12.4    1.1
           AAPL   2018-12-31    322986.6    12.3    7.1  288618.6   1.5 12.4    1.1
2018-12-28 XOM    2018-12-28    326246.7    12.5    7.1  291878.7   1.5 12.6    1.1
           AAPL   2018-12-28    324976.5    12.4    7.1  290608.5   1.5 12.5    1.1
2018-12-27 XOM    2018-12-27    311724.7    11.9    6.8  277356.7   1.5 11.9    1.0
           AAPL   2018-10-27    1137146.7   16.2    14.0 1054517.7  9.2 18.8    4.1
2018-12-26 XOM    2018-10-26    1151491.6   16.4    14.2 1068862.6  9.3 19.0    4.2
           AAPL   2018-10-26    1160185.5   16.5    14.3 1077556.5  9.4 19.2    4.2
2018-12-24 XOM    2018-10-24    1178394.3   16.7    14.5 1095765.3  9.5 19.5    4.3
           AAPL   2018-10-24    1185590.9   16.8    14.6 1102961.9  9.6 19.7    4.3

DataFrame.set_indexDataFrame.sort_index DataFrame.set_index使用:

df1 = df.set_index(['date', 'ticker']).sort_index(level=[0,1], ascending=[True, False])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM