Back to Browse

Max & Min in Python (5 Examples) | Maxima & Minima in List & DataFrame | Columns, Rows & By Group

802 views
Oct 3, 2022
7:38

How to find the maximum and minimum in a list and the columns of a pandas DataFrame in the Python programming language. More details: https://statisticsglobe.com/max-min-python Python code of this video: my_list = [1, 4, 2, 9, 7, 2, 1, 8, 3, 3, 2, 1] # Create example list print(my_list) # Print example list # [1, 4, 2, 9, 7, 2, 1, 8, 3, 3, 2, 1] print(max(my_list)) # Get max of list # 9 print(min(my_list)) # Get min of list # 1 import pandas as pd # Import pandas library to Python data = pd.DataFrame({'x1':[5, 2, 4, 2, 2, 3, 9, 1, 7, 5], # Create pandas DataFrame 'x2':range(10, 20), 'group':['A', 'A', 'B', 'B', 'C', 'A', 'C', 'C', 'A', 'B']}) print(data) # Print pandas DataFrame print(data['x1'].max()) # Get max of one column # 9 print(data['x1'].min()) # Get min of one column # 1 print(data.max()) # Get max of all columns # x1 9 # x2 19 # group C # dtype: object print(data.min()) # Get min of all columns # x1 1 # x2 10 # group A # dtype: object print(data.max(axis = 1)) # Get max of rows # 0 10 # 1 11 # 2 12 # 3 13 # 4 14 # 5 15 # 6 16 # 7 17 # 8 18 # 9 19 # dtype: int64 print(data.min(axis = 1)) # Get max of rows # 0 5 # 1 2 # 2 4 # 3 2 # 4 2 # 5 3 # 6 9 # 7 1 # 8 7 # 9 5 # dtype: int64 print(data.max(axis = 1, numeric_only = True)) # Get max of rows # x1 x2 # group # A 7 18 # B 5 19 # C 9 17 print(data.min(axis = 1, numeric_only = True)) # Get min of rows # x1 x2 # group # A 2 10 # B 2 12 # C 1 14 Follow me on Social Media: Facebook – Statistics Globe Page: https://www.facebook.com/statisticsglobecom/ Facebook – R Programming Group for Discussions & Questions: https://www.facebook.com/groups/statisticsglobe Facebook – Python Programming Group for Discussions & Questions: https://www.facebook.com/groups/statisticsglobepython LinkedIn – Statistics Globe Page: https://www.linkedin.com/company/statisticsglobe/ LinkedIn – R Programming Group for Discussions & Questions: https://www.linkedin.com/groups/12555223/ LinkedIn – Python Programming Group for Discussions & Questions: https://www.linkedin.com/groups/12673534/ Twitter: https://twitter.com/JoachimSchork Music by bensound.com

Download

0 formats

No download links available.

Max & Min in Python (5 Examples) | Maxima & Minima in List & DataFrame | Columns, Rows & By Group | NatokHD