我有一个数据帧df
,如图所示,当按前两列分组时,我需要找到列c3_x
的最后一个值。
代码段:
df
c1_states c2_cities c3_x
0 State1 City1 5
1 State1 City1 2
2 State2 City2 8
3 State3 City3 7
预期输出:
c3_x
c1_states c2_cities
State1 City1 2
State2 City2 8
State3 City3 7
我尝试过的事情和遇到的困难:
df.groupby(['c1_states', 'c2_cities'])['c3_x'].apply(lambda x: x) # Stuck