Pandas DataFrame is two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns).
Let’s see how can we get the index of maximum value in DataFrame column.
Observe this dataset first. We’ll use ‘Weight’ and ‘Salary’ columns of this data in order to get the index of maximum values from a particular column in Pandas DataFrame.
# importing pandas module import pandas as pd # making data frame df.head(10) |

Code #1: Check the index at which maximum weight value is present.
# importing pandas module import pandas as pd # making data frame df = pd.read_csv("nba.csv") # Returns index of maximum weight df[['Weight']].idxmax() |
Output:

We can verify whether the maximum value is present in index or not.
# importing pandas module import pandas as pd # making data frame df = pd.read_csv("nba.csv") # from index 400 to 409 df.iloc[400:410] |
Output:

Code #2: Let’s insert a new row at index 0, having maximum salary and then varify.
# importing pandas module import pandas as pd # making data frame df = pd.read_csv("nba.csv") new_row = pd.DataFrame({'Name':'Geeks', 'Team':'Boston', 'Number':3, 'Position':'PG', 'Age':33, 'Height':'6-2', 'Weight':189, 'College':'MIT', 'Salary':999999999} , index=[0]) df = pd.concat([new_row, df]).reset_index(drop=True) df.head(5) |
Output:

Now, let’s check if the maximum salary is present at index 0 or not.
# Returns index of minimum salary df[['Salary']].idxmax() |
Output:

Recommended Posts:
- Create a DataFrame from a Numpy array and specify the index column and column headers
- Get column index from column name of a given Pandas DataFrame
- Get the index of minimum value in DataFrame column
- How to Convert Index to Column in Pandas Dataframe?
- How to convert index in a column of the Pandas dataframe?
- How to Convert Dataframe column into an index in Python-Pandas?
- How to Sort a Pandas DataFrame based on column names or row index?
- Return the Index label if some condition is satisfied over a column in Pandas Dataframe
- How to get column and row names in DataFrame?
- Get a list of a specified column of a Pandas DataFrame
- How to add Empty Column to Dataframe in Pandas?
- Add column names to dataframe in Pandas
- How to get column names in Pandas dataframe
- Delete a column from a Pandas DataFrame
- Split a column in Pandas dataframe and get part of it
- Capitalize first letter of a column in Pandas dataframe
- Check whether a given column is present in a Pandas DataFrame or not
- Apply uppercase to a column in Pandas dataframe
- How to lowercase column names in Pandas dataframe
- Get unique values from a column in Pandas DataFrame
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

