Descriptive Statistics - count & sum
F. Count() - counts the non-NA entries for each row and column. Values None, Nat, NaN are considered as NA in pandas.
Example:-
Output:-
2016 4
2017 4
2018 2
2019 2
2. import pandas as pd
G. Sum() - Returns the sum of the values for the requested axis.
2016 97000
2017 AAAD
2018 105500
2. import pandas as pd
q2 51500.0
q3 47000.0
q4 49000.0
Example:-
1. 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},2019:{'q1':True,'q2':'False'}})
print(df2.count())
2016 4
2017 4
2018 2
2019 2
2. 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},2019:{'q1':True,'q2':'False'}})
print(df2.count(numeric_only=True))
Output:-
2016 4
2018 2
Example:-
1. 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},2019:{'q1':True,'q2':'False'}})
print(df2.sum())
Output:-
2017 AAAD
2018 105500
2. 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},2019:{'q1':True,'q2':'False'}})
print(df2.sum(axis=1))
Output:-
q1 55000.0q2 51500.0
q3 47000.0
q4 49000.0
Comments
Post a Comment