Descriptive Statistics - min(), max()
A. min() - Find out the minimum and maximum out of a given set of data.
Example:-
import pandas as pd
df = pd.DataFrame({2016:{'q1':34500,'q2':56000,'q3':47000,'q4':49000},2017:\{'q1':44900,'q2':46100,'q3':57000,'q4':59000},2018:{'q1':54500,'q2':51000}})
print(df)
Output:-
1. print(df.min())
Output:-
Example:-
import pandas as pd
df = pd.DataFrame({2016:{'q1':34500,'q2':56000,'q3':47000,'q4':49000},2017:\{'q1':44900,'q2':46100,'q3':57000,'q4':59000},2018:{'q1':54500,'q2':51000}})
print(df)
Output:-
2016 | 2017 | 2018 | |
---|---|---|---|
q1 | 34500 | 44900 | 54500.0 |
q2 | 56000 | 46100 | 51000.0 |
q3 | 47000 | 57000 | NaN |
q4 | 49000 | 59000 | NaN |
1. print(df.min())
Output:-
2016 34500.0
2017 44900.0
2018 51000.0
Explanation:
min() finds the minimum among the indexes for each column and axis 0 by default.
2. print(df.min(axis=1))
Output:-
q1 34500.0 q2 46100.0 q3 47000.0 q4 49000.0
Explanation:
min(axis=1) finds the minimum among the columns for each indexes.
import pandas as pd
df2 = pd.DataFrame({2016:{'q1':34500,'q2':56000,'q3':47000,'q4':49000},2017:{'q1':'A','q2':'B','q3':'C','q4':'D'},2018:{'q1':54500,'q2':51000}})print(df)
2016 | 2017 | 2018 | |
---|---|---|---|
q1 | 34500 | A | 54500.0 |
q2 | 56000 | B | 51000.0 |
q3 | 47000 | C | NaN |
q4 | 49000 | D | NaN |
3. print(df2.min())
Output:-
2016 34500 2017 A 2018 51000
Explanation:-
min() calculates the minimum skipping the NaN(Not a number) values because default
value of skipna is True.
4.print(df2.min(skipna=False))
Output:-
2016 34500 2017 A 2018 NaN
Explanation:-
skipna=False means not to skip NaN values while finding the minimum.
5. print(df2.min(numeric_only=True))
Output:-
2016 34500.0 2018 51000.0Explanation:-
With numeric_only=True min() function skipped string values of column 2017B. max() - Finds maximum value among a series of value.Do it yourself
print(df.max())print(df.max(axis=1))print(df2.max(skipna=False))print(df2.max(numeric_only=True))print(df2.max(axis=1,skipna=False,numeric_only=True))
#Post your answers in comments
Comments
Post a Comment