Pandas以奇怪的格式返回数据(Int64、Float64)

2024-09-29 23:22:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用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

这是为什么?这意味着什么?假设我想使用这些值(例如求和)。这会导致问题吗?有没有办法告诉熊猫,我只是想要这些价值观而不是别的


Tags: namepandasdfindextime详细信息max常规
2条回答

您的结果似乎是一个由数据类型的索引和值表示的元组,这可能是因为pandas中的某些循环后端。更简单的方法是直接查询最大值的索引:

# gets the index of max time
seed_row_idx = df.veghel_time.idxmax()

# get the value of some column at that index
my_value = df.iloc[seed_row_idx, "Lat"]

它仍然是数据帧的一行

如果您需要将普通值用于非特定的内容,可以对其使用.squeeze()(或其他类型)来获取普通值

相关问题 更多 >

    热门问题