我在python中有一个数据帧,如下所示:
  time                 A    B    C      D  E  F
0 2019-12-19 15:00:00  foo  one  small  1  2  2
1 2019-12-19 15:00:30  foo  one  large  2  4  4
2 2019-12-19 15:01:00  foo  one  large  2  5  5
3 2019-12-19 15:01:30  foo  two  small  3  5  5
4 2019-12-19 15:02:00  foo  two  small  3  6  6
5 2019-12-19 15:02:30  bar  one  large  4  6  6
6 2019-12-19 15:03:00  bar  one  small  5  8  8
7 2019-12-19 15:03:30  bar  two  small  6  9  9
8 2019-12-19 15:04:00  bar  two  large  7  9  9如何通过dolphindb python orca api获取以下数据帧?
E    2    4    5     6  8    9
A                               
bar  NaN  NaN  NaN   4  5.0  13.0
foo  1.0  2.0  5.0   3  NaN   NaN数据帧中的数字表示相同A和E中的sum(D)。
发布于 2020-06-01 11:16:54
在pandas中,您可以按pd.pivot_table(df, values='D', index='A', columns='E', aggfunc='sum')透视表。对于Orca,只需用orca替换pd即可
orca.pivot_table(df, values='D', index='A', columns='E', aggfunc='sum')它返回以下DataFrame:
E     C2   C4   C5  C6   C8    C9
A
bar  NaN  NaN  NaN   4  5.0  13.0
foo  1.0  2.0  5.0   3  NaN   NaN如您所见,DataFrame的列名中有一个额外的前缀'C‘。这是因为DolphinDB不允许列名以数字开头。
https://stackoverflow.com/questions/60427832
复制相似问题