-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdensity_plot_from_dataframe.py
43 lines (32 loc) · 1.12 KB
/
density_plot_from_dataframe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#Distribution of Z Scores of Ages by Density of Cocktails
import matplotlib.pyplot as plt
import pandas as pd
#creates density plot out of dataframe
import numpy as np
plt.style.use('fivethirtyeight')
#read the df
df = pd.read_csv('C:\Users\OnoTation\Desktop\AllCsvs\cocktail_ids_age_gender.csv')
df.values
print df
#calculate the frequency distribution by age and gender of drugs
counts = df.groupby(['Age','Gender']).count()
#calculate the mean age of the patients
meanAge = df.ix[:,1:].mean()
print meanAge
#calculate the standard deviation of the age
sdAge = df.ix[:,1:].std()
print sdAge
#apply formula
df1 = (df.ix[:,1:] - df.ix[:,1:].mean()) / df.ix[:,1:].std()
df1['Gender'] = df['Gender']
print df1
counts1 = df1.groupby(['Age']).count()
#print counts1
#generate density plot
ax1 = df1.plot(kind='kde', figsize=(10, 6))
arr = ax1.get_children()[0]._x
plt.xticks(np.linspace(arr[0], arr[-1]), rotation=45)
plt.ylabel('Density Of Cocktails',fontsize=20)
plt.title('Distribution Of Z Scores Of Ages By Density Of Cocktails',fontsize=40)
plt.xlabel('Z Scores')
plt.show()