我正在使用pandas,我需要某行的索引,其中某个值是最大的。为此,我使用seed_row = df[df["veghel_time"] == df.veghel_time.max()]
获取列df["veghel_time"]
具有最大值的行(详细信息不重要)
当我使用print(seed_row_df.index)
而不是常规索引值(在本例中为126)时,我得到:
Int64Index([126], dtype='int64')
同样地,print(seed_row_df["veghel_time"])
给了我
126 119
Name: veghel_time, dtype: int64
而不仅仅是列的值,即119
最后,print(seed_row_df["Lat"])
给出:
126 6.57619
Name: Long, dtype: float64
而不是简单地6.57619
这是为什么?这意味着什么?假设我想使用这些值(例如求和)。这会导致问题吗?有没有办法告诉熊猫,我只是想要这些价值观而不是别的
您的结果似乎是一个由数据类型的索引和值表示的元组,这可能是因为pandas中的某些循环后端。更简单的方法是直接查询最大值的索引:
它仍然是数据帧的一行
如果您需要将普通值用于非特定的内容,可以对其使用
.squeeze()
(或其他类型)来获取普通值相关问题 更多 >
编程相关推荐