数据
data = [['john', 0.20, 0.0, 0.4, 0.40],['katty', 0.0, 1.0, 0.0, 0.0],['kent', 0.0, 0.51, 0.49, 0.0]]
df = pd.DataFrame(data, columns=['name','fruit', 'vegetable', 'softdrinks', 'icecream'])
df = df.set_index('name')
df.head()
期望的结果
data = [['john', 0.20, 0.0, 0.4, 0.40,'softdrinks','icecream'],['katty', 0.0, 1.0, 0.0, 0.0,'vegetable','NaN'],['kent', 0.0, 0.51, 0.49, 0.0,'vegetable','softdrinks']]
df = pd.DataFrame(data, columns=['name','fruit', 'vegetable', 'softdrinks', 'icecream', 'max_no1', 'max_no2'])
df = df.set_index('name')
df.head()
试过idxmax里面只返回值最高的列名,我需要定位值第二高的行列名,怎么实现这个?你知道吗
多谢了
首先按^{} 将} 重新整形,对于top2使用^{} ,最后按^{} 重新整形数据^{} :
0
设置为缺失值,然后按^{或使用^{} 从注释中选择解决方案,并通过与
numpy
中的广播比较再次设置缺少的值:相关问题 更多 >
编程相关推荐