filmov
tv
Get Max & Min Value of Column & Index in pandas DataFrame in Python (2 Examples) | idxmax() Function
Показать описание
Python code of this video:
import pandas as pd # Load pandas library
data = pd.DataFrame({'x1':[3, 2, 7, 1, 9, 3, 4], # Create example DataFrame
'x2':[2, 1, 1, 3, 1, 2, 3],
'x3':range(7, 0, - 1)})
print(data) # Print example DataFrame
my_max = data['x1'].loc[data['x1'].idxmax()] # Maximum in column
print(my_max)
# 9
my_min = data['x1'].loc[data['x1'].idxmin()] # Minimum in column
print(my_min)
# 1
my_max_ind = data['x1'].idxmax() # Index of maximum in column
print(my_max_ind)
# 4
my_min_ind = data['x1'].idxmin() # Index of minimum in column
print(my_min_ind)
# 3
Follow me on Social Media:
import pandas as pd # Load pandas library
data = pd.DataFrame({'x1':[3, 2, 7, 1, 9, 3, 4], # Create example DataFrame
'x2':[2, 1, 1, 3, 1, 2, 3],
'x3':range(7, 0, - 1)})
print(data) # Print example DataFrame
my_max = data['x1'].loc[data['x1'].idxmax()] # Maximum in column
print(my_max)
# 9
my_min = data['x1'].loc[data['x1'].idxmin()] # Minimum in column
print(my_min)
# 1
my_max_ind = data['x1'].idxmax() # Index of maximum in column
print(my_max_ind)
# 4
my_min_ind = data['x1'].idxmin() # Index of minimum in column
print(my_min_ind)
# 3
Follow me on Social Media: