WorksheetsL13 Python
Total questions: 37
Worksheet time: 37mins
Output of this code?
import pandas as pd
s = pd.Series([1,2,3,4,5]) s.mean ()
3.0
Output of this code?
s = pd.Series ([1,2,3,4,5]) s.median()
Output of this code?
s = pd.Series ([1,2,2,3,4]) s.mode()
How do you compute variance using pandas?
s.var()
Output of this code? import pandas as pd
s = pd. Series ([1,2,3,4,5]) s.mean()
How do you compute standard deviation using pandas?
s.std()
Output of this code?
import numpy as np
np.var([1,2,3,4])
Output of this code?
np.std ([1,2, 3,4])
What is covariance?
Measure of distribution
Output of this code?
df = pd. DataFrame ({'X': [1,2,3], 'Y': [4,5,6]})
df.cov()
X Y X 1.0 1.0 Y 1.0 1.0
X Y X 0 0 Y 0 0
Produces error
Returns series
Output of this code?
df.corr()
Output of this code?
s = pd. Series ([1, 2, 3, 4, 5])
s.describe()
How do you compute quantiles?
s.quantile(0.25)
Output of this code?
from scipy.stats import zscore
import pandas as pd
a = pd.Series([1,2,3,4,5]).zscore(s)
How do you compute cumulative sum?
s.cumsum ()
How do you compute cumulative product?
s.cumprod ()
How do you compute correlation between two series?
s1.corr(s2)
What does this code output?
df = pd.DataFrame ({'A': (1,2,3,4, 5]})
df.var()
How do you compute sample standard deviation in numpy?
np.std([1,2, 3, 4], ddof=1)
How do you compute sample variance in numpy?
np.var ([1,2, 3,4], ddof=1)
What is the output?
s = pd.Series ( [1,2,3,4,5])
s.max () - s.min ()
How do you compute range of a series?
s.ptp()
How do you compute interquartile range?
s.quantile(0.75) - s. quantile(0.25)
What will be the output of this code?
import pandas as pd
import numpy as np
df = pd.DataFrame ({'A': [1,2,3,4,5], 'B': [5,4,3,2,1]})
df.corr (method = 'kendall')
What will be the output of this code?
s = pd.Series ([1,2,2,3, 3,3, 4, 4,4,4])
s.value_counts(normalize=True)
What does this code compute?
s = pd.Series.([1,2,3,4,5])
np.mean(np.square (s-s.mean ()))
Output of this code?
s = pd.Series ([1,2,3,4,5])
((s - s.mean ()) / s.std()).sum()
What does this code compute?
df = pd.DataFrame ({'A': [1,2,3,4,5], 'B': [2,4, 6,8,10]})
df.apply(lambda x: (x - x.mean ()) / x.std ())
Output of this code?
s = pd.Series([1,2,3,4,5])
s.rolling(3).apply (lambda x: np.prod (x))
What will be the output of this code?
from scipy.stats import pearsonr
x = [1,2,3,4,5]
y = [2,3,5,7,11]
pearsonr(x,y)
What will this code output?
df = pd.DataBrameK({At: [1,2,3/4,5]})
df.diff().sum()
