<jupyter_start><jupyter_text>Theory of Statistics  Mean of a dataframe:<jupyter_code>import pandas as pd
import numpy as np
 
#Create a DataFrame
d = {
    'Name':['Alisa','Bobby','Cathrine','Madonna','Rocky','Sebastian','Jaqluine',
   'Rahul','David','Andrew','Ajay','Teresa'],
   'Score1':[62,47,55,74,31,77,85,63,42,32,71,57],
   'Score2':[89,87,67,55,47,72,76,79,44,92,99,69]}
 
 
df = pd.DataFrame(d)
df<jupyter_output><empty_output><jupyter_text>mean of the dataframe<jupyter_code>df.mean()<jupyter_output><empty_output><jupyter_text>Column Mean of the dataframe:<jupyter_code>df.mean(axis=0)<jupyter_output><empty_output><jupyter_text>axis=0 argument calculates the column wise mean of the dataframe<jupyter_code># Row Mean of the dataframe:<jupyter_output><empty_output><jupyter_text>df.mean(axis=1)<jupyter_code>axis=1 argument calculates the row wise mean of the dataframe<jupyter_output><empty_output><jupyter_text>Lets Calculate the mean of the specific Column<jupyter_code>df.loc[:,"Score1"].mean()<jupyter_output><empty_output><jupyter_text>In class lab exercise :Calculate the mean of the column "score2"?  Median Function in Python  Lets calculate Simple median function<jupyter_code>import statistics
print(statistics.median([1,9,5,6,8,7]))
print(statistics.median([4,-11,-5,16,5,7,9]))<jupyter_output>6.5
5<jupyter_text>Median of a dataframe:<jupyter_code>import pandas as pd
import numpy as np
 
#Create a DataFrame
d = {
    'Name':['Alisa','Bobby','Cathrine','Madonna','Rocky','Sebastian','Jaqluine',
   'Rahul','David','Andrew','Ajay','Teresa'],
   'Score1':[62,47,55,74,31,77,85,63,42,32,71,57],
   'Score2':[89,87,67,55,47,72,76,79,44,92,99,69],
   'Score3':[56,86,77,45,73,62,74,89,71,67,97,68]}
 
df1 = pd.DataFrame(d)
df1
df1.median()<jupyter_output><empty_output><jupyter_text>the above code will calculate the median of the dataframe across columns<jupyter_code># Column Median of the dataframe:<jupyter_output><empty_output><jupyter_text>df1.median(axis=0)<jupyter_code>axis=0 argument calculates the column wise median of the dataframe<jupyter_output><empty_output><jupyter_text>Calculate the median of the specific Column<jupyter_code>df1.loc[:,"Score1"].median()<jupyter_output><empty_output><jupyter_text>the above code calculates the median of the “Score1” column<jupyter_code># # In class lab exercise :
Calculate the median of the column "score2"?
# Mode Function in Python pandas
# Simple mode function in python<jupyter_output><empty_output><jupyter_text>import statistics print(statistics.mode([1,5,5,7,5,6,8,7]))print(statistics.mode(['lion', 'cat', 'cat','dog','tiger']))<jupyter_code># Mode of a dataframe:<jupyter_output><empty_output><jupyter_text>import pandas as pdimport numpy as np Create a DataFramed = {    'Name':['Alisa','Bobby','Cathrine','Madonna','Rocky','Sebastian','Jaqluine',   'Rahul','David','Andrew','Ajay','Teresa'],   'Score1':[62,47,55,74,47,77,85,63,42,32,71,57],   'Score2':[89,87,67,55,47,72,76,79,44,67,99,69],   'Score3':[56,86,77,45,73,62,74,89,71,67,97,68]}   df2 = pd.DataFrame(d)df2 df2.mode()<jupyter_code># Column Mode of the dataframe<jupyter_output><empty_output><jupyter_text>df2.mode(axis=0)<jupyter_code>axis=0 argument calculates the column wise mode of the dataframe<jupyter_output><empty_output><jupyter_text>Row Mode of the dataframe<jupyter_code>df2.mode(axis=1)<jupyter_output>C:\Users\DELL\Anaconda3\lib\site-packages\pandas\core\algorithms.py:838: UserWarning: Unable to sort modes: '<' not supported between instances of 'str' and 'int'
  warn("Unable to sort modes: {error}".format(error=e))
C:\Users\DELL\Anaconda3\lib\site-packages\pandas\core\algorithms.py:838: UserWarning: Unable to sort modes: '<' not supported between instances of 'int' and 'str'
  warn("Unable to sort modes: {error}".format(error=e))<jupyter_text>axis=1 argument calculates the row wise mode of the dataframe<jupyter_code># Lets calculate the mode of the specific Column<jupyter_output><empty_output><jupyter_text>df.loc[:,"Score1"].mode()<jupyter_code># WAP - In class exe :Calculate the mode of the column "score2"?
# Range() function in Python
# range() function with one parameter<jupyter_output><empty_output><jupyter_text>list(range(3))<jupyter_code># with two parameter<jupyter_output><empty_output><jupyter_text>list(range(1,7))range(start,stop)<jupyter_code># Lets try passing arguments where the first is greater than the second.<jupyter_output><empty_output><jupyter_text>list(range(7,1))<jupyter_code>#it returns an empty list because 7 falls to the right of 1, and it traverses to the right from 7. Therefore, it never reaches 1.<jupyter_output><empty_output><jupyter_text>list(range(-7,3)) list(range(-7,-3))<jupyter_code># # In class lab exercise :
What will happen if you pass the parameter as (-3,-7)?
# Range() function with three parameters<jupyter_output><empty_output><jupyter_text>list(range(7,1,-1))range(start,stop,interval) list(range(7,1,-2)) list(range(1,7,0))<jupyter_code>#It raised a value error, because the interval cannot be zero if you need to go from one number to another.<jupyter_output><empty_output><jupyter_text>list(range(1,7,1.5))<jupyter_code>#Note that all three arguments must be integers only.<jupyter_output><empty_output><jupyter_text>In class lab exercise :What will happen if you pass the parameter as (12,2,2)?  Zscore<jupyter_code>from scipy.stats import zscore
zscore([1, 2, 3])
zscore([[1, 2, 3],[6, 7, 8]], axis=1)<jupyter_output><empty_output><jupyter_text>Standard Deviation  Simple Standard deviation Function in Python<jupyter_code>import numpy as np
 
print(np.std([1,9,5,6,8,7]))
print(np.std([4,-11,-5,16,5,7,9]))<jupyter_output>2.581988897471611
8.312763729129232<jupyter_text>Standard deviation of a dataframe:<jupyter_code>import pandas as pd
import numpy as np
 
#Create a DataFrame
d = {
    'Name':['Alisa','Bobby','Cathrine','Madonna','Rocky','Sebastian','Jaqluine',
   'Rahul','David','Andrew','Ajay','Teresa'],
   'Score1':[62,47,55,74,31,77,85,63,42,32,71,57],
   'Score2':[89,87,67,55,47,72,76,79,44,92,99,69],
   'Score3':[56,86,77,45,73,62,74,89,71,67,97,68]}
 
 
 
df3 = pd.DataFrame(d)
df3
df3.std()<jupyter_output><empty_output><jupyter_text>Column Standard deviation of the dataframe:<jupyter_code>df3.std(axis=0)<jupyter_output><empty_output><jupyter_text>axis=0 argument calculates the column wise standard deviation of the dataframe<jupyter_code># Row standard deviation of the dataframe:<jupyter_output><empty_output><jupyter_text>df3.std(axis=1)<jupyter_code>axis=1 argument calculates the row wise standard deviation of the dataframe<jupyter_output><empty_output><jupyter_text>Lets Calculate the standard deviation of the specific Column<jupyter_code>df3.loc[:,"Score1"].std()<jupyter_output><empty_output><jupyter_text>In class lab exercise :Calculate the Standard deviation of the column "score2"?  coefficient of Correlation<jupyter_code>df3.corr()
df3.corr(method="pearson")
df3.cov()<jupyter_output><empty_output><jupyter_text>Skewness and Kurtosis<jupyter_code>df3.kurtosis()
df3.skew()<jupyter_output><empty_output><jupyter_text>Lets perform the above concepts using a real life example<jupyter_code>import pandas as pd 
import numpy as np
import csv
data = pd.read_csv("C:/Users/DELL/Desktop/wine.csv", encoding="latin-1")
data.head()
data.tail()
df = pd.DataFrame(data)
print (df)<jupyter_output>Unnamed: 0      country  \
0                0        Italy   
1                1     Portugal   
2                2           US   
3                3           US   
4                4           US   
5                5        Spain   
6                6        Italy   
7                7       France   
8                8      Germany   
9                9       France   
10              10           US   
11              11       France   
12              12           US   
13              13        Italy   
14              14           US   
15              15      Germany   
16              16    Argentina   
17              17    Argentina   
18              18        Spain   
19              19           US   
20              20           US   
21              21           US   
22              22        Italy   
23              23           US   
24              24        Italy   
25              25           US   
26              26        Italy   
27              27  [...]<jupyter_text>Lets find out the mean of the points<jupyter_code>data['points'].mean() #Mean of the dataframe:<jupyter_output><empty_output><jupyter_text>Lets calculate the median of the specific Column¶<jupyter_code>data['points'].median()<jupyter_output><empty_output><jupyter_text>Lets calculate the mode of the specific column<jupyter_code>data['points'].mode()<jupyter_output><empty_output><jupyter_text>Lets calculate the standard deviation of a data frame¶<jupyter_code>df.std()<jupyter_output><empty_output><jupyter_text>Lets calculate the standard deviation of the data frame column wise<jupyter_code>df.std(axis=0)<jupyter_output><empty_output><jupyter_text>In class lab exercise :Calculate the standard deviation of the data frame row wise?  Lets calculate the standard deviation of a specefic column "points"<jupyter_code>df.loc[:,"points"].std()<jupyter_output><empty_output><jupyter_text>In class lab exercise :Calculate the standard deviation of a specefic column "price"?  Lets check for the zscore<jupyter_code>from scipy.stats import zscore
zscore(df.loc[:,"points"], axis=0)
df.var()<jupyter_output><empty_output><jupyter_text>In class lab exercise :Calculate the column and row variance of the data frame?  Lets calculate the variance of a specefic column "points"<jupyter_code>df.loc[:,"points"].var()<jupyter_output><empty_output><jupyter_text>In class lab exercise :Calculate the variance of a specefic column "price"?  A complete measures of wine price<jupyter_code># dispersion measures
print('Min price : {0}'.format(df.price.min())) # minimum
print('Max price : {0}'.format(df.price.max())) # maximum
print('price range : {0}'.format(df.price.max()  - df.price.min())) # range
print('25 percentile : {0}'.format(df.price.quantile(.25))) # 25 percentile
print('50 percentile : {0}'.format(df.price.quantile(.5))) # 50 percentile
print('75 percentile : {0}'.format(df.price.quantile(.75))) # 75 percentile
print('Variance price : {0}'.format(df.price.var())) # variance
print('Standard deviation price : {0}'.format(df.price.std())) # standard deviation<jupyter_output>Min price : 4.0
Max price : 3300.0
price range : 3296.0
25 percentile : 17.0
50 percentile : 25.0
75 percentile : 42.0
Variance price : 1682.8223424080645
Standard deviation price : 41.02221766808889<jupyter_text>Lets check the skewness of the data¶<jupyter_code>print('skewness for points : {0:.2f}'.format(df.points.skew()))
print('skewness for price : {0:.2f}'.format(df.price.skew()))<jupyter_output>skewness for price : 18.00<jupyter_text>Lets check the skewness of the data<jupyter_code>print('kurtosis for price : {0:.2f}'.format(df.price.kurtosis()))
print('kurtosis for points : {0:.2f}'.format(df.points.kurtosis()))<jupyter_output>kurtosis for points : -0.30<jupyter_text>Visualization: Seaborne and matplotlib<jupyter_code>import seaborn as sns
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Lets create a small data using numpy array<jupyter_code>import numpy as np
x = np.linspace(0, 6, 11)
y = x ** 2
x
y<jupyter_output><empty_output><jupyter_text>Line Plot<jupyter_code>plt.plot(x, y) 
plt.xlabel('X Axis')
plt.ylabel('Y Axis')
plt.show()<jupyter_output><empty_output><jupyter_text>Histogram<jupyter_code>from random import sample
data = sample(range(1, 1000), 100)
plt.hist(data)
# Plot with a whitegrid style
sns.set()
sns.set_style('whitegrid')
plt.hist(data)<jupyter_output><empty_output><jupyter_text>Lets plot the same histogram with a default seaborn style¶<jupyter_code>sns.set()
plt.hist(data)
plt.show()
plt.clf()
sns.boxplot(data=data)
plt.show()
plt.clf()
plt.scatter(x,y)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13318340829585207, 'fraction_numerical': 0.05422288855572214, 'mean_word_length': 5.2699738903394255, 'pattern_counts': {'":': 0, '<': 196, '<?xml version=': 0, '>': 194, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '50', 'dir': 'jupyter-structured-clean-dedup', 'id': '428246', 'license': 'MIT', 'n_tokens_mistral': 4658, 'n_tokens_neox': 4263, 'n_words': 903, 'path': 'foundation/applied-statistics/class_material_day_3/Data Visualization_Statistics/Case Study(2).ipynb', 'repo_name': 'tejeshreddy/greatlearning-aiml', 'size': '12006'}