Psychotechnopath
Psychotechnopath

Reputation: 2744

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. 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).

When I use print(seed_row_df.index), instead of a regular index value (in this case 126) I get:

Int64Index([126], dtype='int64')

Similarly, print(seed_row_df["veghel_time"]) gives me

126    119
Name: veghel_time, dtype: int64

Instead of simply the value of the column, which is 119.

Finally, print(seed_row_df["Lat"]) gives:

126    6.57619
Name: Long, dtype: float64

Instead of simply 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?

Upvotes: 0

Views: 411

Answers (2)

Yaakov Bressler
Yaakov Bressler

Reputation: 12018

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"]

Upvotes: 1

AKX
AKX

Reputation: 168843

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.

Upvotes: 2

Related Questions