Descriptive Statistics

A number of statistical operations can be performed on the Dataframe and Series objects. This operations are useful in data science to evaluate your data from different perspective. Some common operations are:-
a. abs() - Return a Series/DataFrame with absolute numeric value of each element. Only works on numeric elements.
Example:-
import pandas as pd
import numpy as np s = pd.Series([-1.2,-2.2,3.2])print(s.abs())
Output:-
0 1.2 1 2.2 2 3.2
Explanation:-
  • Converts negative value to positive value.
Example:-
import pandas as pd
import numpy as np s = pd.Series([-1.2,-2.2,1+1j])print(s.abs())
Output:-
0 1.200000 1 2.200000 2 1.414214
Explanation:-
  • Converts negative to positive and complex numbers to absolute number as √a2 +b2
Example:-
import pandas as pd
import numpy as np
#s = pd.Series([-1.2,-2.2,3.2])
df = pd.DataFrame({'Age':[-23,-44,24],'Name':['tim','henry','jerry']})
print(df['Age'].abs())
Output:-
0 23 1 44 2 24

b. all() - Returns True unless there at least one element within a series or along a Dataframe axis that is False or equivalent (e.g. zero or empty).
Example:- 
import pandas as pd
import numpy as np
print(pd.Series([True, False]).all())
Output:-
False
Explanation:-
  • In above Series object two elements are their one is true and other is false.
  • Applying all() function in the series object return False since one of the
element is false.
Example:- 
import pandas as pd
import numpy as np
print(pd.Series([True, True]).all())
Output:-
True
Explanation:-
  • In above Series object two elements are True and True.
  • Applying all() function in the series object return True since both of the
elements are true.
Example:- 
import pandas as pd
import numpy as np


df = pd.DataFrame({'col1': [True, True], 'col2': [True, False]})
print(df.all())
Output:-
col1 True col2 False
Explanation:-
  • In above Series object two elements are True and True.
  • Applying all() function in the series object return True since both of the
elements are true.
Quiz:-
1.import pandas as pd
import numpy as np
#s = pd.Series([-1.2,-2.2,3.2])
df = pd.DataFrame({'Age':[-23,-44,24],'Name':['tim','henry','jerry']})
print(df.abs())
#Post your answers in the comments

Comments

Popular posts from this blog

Python Tokens

Python Tokens - Operators

Descriptive Statistics - count & sum