【发布时间】:2016-12-10 06:41:27
【问题描述】:
我有一个 df,它在最左边的列中有一些代码,在其他列中有一个正向配置文件(下面的 df1)
df1:
code tp1 tp2 tp3 tp4 tp5 tp6 \
0 1111 0.000000 0.000000 0.018714 0.127218 0.070055 0.084065
1 222 0.000000 0.000000 0.000418 0.000000 0.017540 0.003015
2 333 1.146815 1.305678 0.384918 0.688284 0.000000 0.000000
3 444 0.000000 0.000000 1.838797 0.000000 0.000000 0.000000
4 555 27.190002 27.134837 24.137560 17.739465 11.990806 8.631395
5 666 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
tp7 tp8 tp9 tp10
0 0.019707 0.000000 0.000000 0.000000
1 6.594860 10.535905 15.697232 21.035824
2 0.000000 0.000000 0.000000 0.000000
3 0.000000 0.000000 0.000000 0.000000
4 7.476197 6.461532 5.570051 4.730345
5 0.000000 0.000068 0.000000 0.000000
我希望输出为 3 列 df(下面的 df2),其中包含单元格的列名(对于每个代码),其中包含最后一个数字(+ve 或 -ve),之后只有 0。第 2 列 (tp_with_max_num) 将具有最大此类数的列名。
df2:
code max_tp tp_with_max_num
0 1111 tp7 tp4
1 222 tp10 tp10
2 333 tp4 tp2
3 444 tp3 tp3
4 555 tp10 tp1
5 666 tp8 tp8
使用这个:name of column, that contains the max value 我能够获得第三列:
input_df['tp_with_max_num'] = input_df.ix[0:6,1:].apply(lambda x: input_df.columns[1:][x == x.max()][0], axis=1)
我无法解决 df2 中的第 2 列....
【问题讨论】:
标签: python pandas dataframe max cumsum