如何分组两列并保持其余列相同?

时间:2017-12-14 19:13:05

标签: python pandas pandas-groupby

DataFrame看起来像这样:

Date       Symbol    Open     High    Low    Close   Volume

2016-01-04  AAPL    102.61  105.368  102.00  105.35  67649387.0
2016-01-05  AAPL    105.75  105.850  102.41  102.71  55790992.0
2016-01-06  KO      100.56  102.370  99.87   100.70  68457388.0

我试图让它看起来像这样:

                          Open    High     Low       Close    Volume
Symbol     Date
 AAPL      2016-01-04    102.61   105.368  102.00    105.35  67649387.0
           2016-01-05    105.75   105.850  102.41    102.71  55790992.0
           2016-01-06    100.56   102.370  99.87     100.70  68457388.0

 KO        2016-01-04    102.61   105.368  102.00    105.35  67649387.0
           2016-01-05    102.61   105.368  102.00    105.35  67649387.0
           2016-01-06    102.61   105.368  102.00    105.35  67649387.0

我试过了:

  mydata.groupby(['Symbol','Date']).agg()

我也尝试过reset_index并合并索引,但没有成功

1 个答案:

答案 0 :(得分:2)

如果我明白你的观点..

@ApiMethod(..., path = "/test/imprimirPersona")