[英]Pandas returning data in a weird format (Int64, Float64)
I'm working with pandas, and I need the index of some row where some value is Max.我正在使用熊猫,我需要某些值为 Max 的行的索引。 To do this I use
seed_row = df[df["veghel_time"] == df.veghel_time.max()]
To get the row where the column df["veghel_time"]
has the maximum value (details not important).为此,我使用
seed_row = df[df["veghel_time"] == df.veghel_time.max()]
获取列df["veghel_time"]
具有最大值的行(细节不重要)。
When I use print(seed_row_df.index)
, instead of a regular index value (in this case 126) I get:当我使用
print(seed_row_df.index)
而不是常规索引值(在本例中为 126)时,我得到:
Int64Index([126], dtype='int64')
Similarly, print(seed_row_df["veghel_time"])
gives me同样,
print(seed_row_df["veghel_time"])
给了我
126 119
Name: veghel_time, dtype: int64
Instead of simply the value of the column, which is 119
.而不是简单的列的值,即
119
。
Finally, print(seed_row_df["Lat"])
gives:最后,
print(seed_row_df["Lat"])
给出:
126 6.57619
Name: Long, dtype: float64
Instead of simply 6.57619
而不是简单的
6.57619
Why is this, and what are the implications of this?为什么会这样,这有什么影响? Say I want to use these values (For instance sum them).
假设我想使用这些值(例如对它们求和)。 Will this lead to problems?
这会导致问题吗? Is there a way to tell pandas that I simply want the values and nothing else?
有没有办法告诉熊猫我只想要值而不是别的?
It's still a single row of a dataframe.它仍然是数据框的一行。
You can use .squeeze()
on it (or other types) to get the plain value out if you need it for something non-pandas.如果您需要非熊猫的东西,您可以在它(或其他类型
.squeeze()
上使用.squeeze()
来获取普通值。
It appears that your result is a tuple represented by the index and value of the data type – perhaps because of some cyclical backend in pandas.看起来你的结果是一个由数据类型的索引和值表示的元组——也许是因为熊猫中的一些循环后端。 A simpler approach would be to query the index of the max value directly:
一种更简单的方法是直接查询最大值的索引:
# 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"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.