Get index value from pandas dataframe
14,201
call the index directly
return countries.index[2]
but what you post here looks like a pandas dataframe instead of a series - if that's the case do
countries['Country_Name'].iloc[2]
Related videos on Youtube
Author by
beshr
Updated on June 04, 2022Comments
-
beshr almost 2 years
I have a Pandas dataframe (countries) and need to get specific index value. (Say index 2 => I need Japan)
I used iloc, but i got the data (7.542)
return countries.iloc[2] 7.542
-
Umar.H over 3 yearsyou sure it's a series and not a dataframe?
-
Kaleb Coberly over 3 yearsMaybe the confusion has to do with the fact that each column in a dataframe is a series. @beshr, are you operating on a column (or columns) in a dataframe, or just handling the dataframe directly?
-
questionto42standswithUkraine almost 3 yearsDownvote. Since the edit queue is full: the header is very vague. You want to get the value from a chosen index of a df. One might read the header as if you search for the index value(s) for a given df value.
-
-
Kaleb Coberly over 3 yearsthe second solution didn't work on my dataframe, but the first solution did. The second solution works for accessing a value in a column. If you want the index of the value of a column, you would do
countries['Country_Name'].index[2]