我正在尝试使用pandas处理一些.csv数据,我正在努力处理一些我确信是新手的举动,但在花了很多时间尝试使之生效后,我需要你的帮助。
本质上,我试图在我创建的数据帧中找到一个值的索引。
max = cd_gross_revenue.max()
#max value of the cd_gross_revenue dataframe
print max
#finds max value, no problem!
maxindex = cd_gross_revenue.idxmax()
print maxindex
#finds index of max_value, what I wanted!
print max.index
#ERROR: AttributeError: 'numpy.float64' object has no attribute 'index'
maxindex变量使用idxmax()得到答案,但是如果我不寻找最大值的索引呢?如果我看到的是某个随机值的索引,我该怎么做呢?显然,索引在这里对我不起作用。
提前感谢您的帮助!
使用
boolean mask
获取值等于随机变量的行。 然后使用该掩码索引数据帧或序列。 然后使用pandas数据帧或系列的.index
字段。例如:s[s==13]
例如
当您调用idxmax时,它返回索引中与最大值对应的键。您需要将该键传递给dataframe以获取该值。
相关问题 更多 >
编程相关推荐