Descriptive statistics - mode(), mean() and median()
C. mode() - returns the value that appears most from a set of values. Example:- 1. import pandas as pd import pandas as pd df2 = pd.DataFrame({2016:{'q1':500,'q2':500,'q3':47000,'q4':49000},2017:{'q1':'A','q2':'A','q3':'A','q4':'D'},2018:{'q1':54500,'q2':51000}}) df2.mode() Output:- 2016 2017 2018 0 500.0 A 51000.0 1 NaN NaN 54500.0 Explanation:- Since by default axis=0 so mode is calculated among rows(indexes) i.e for each column. 2. df2.mode(axis=1) 0 1 2 q1 500 A 54500.0 q2 500 A 51000.0 q3 47000 A NaN q4 49000 D NaN Explanation:- Since axis=1 so the mode is calculated among columns i.e for each row. 3. df2.mode(numeric_only=True) Output:- 2016 2018 0 500.0 51000.0 1 NaN 54500.0 Explanation: With numeric_only=True only numeric values are included for mode calculation and String/Text values are not considered. By...
Comments
Post a Comment