-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmosaic (occupation) - Copy.py
34 lines (22 loc) · 1.05 KB
/
mosaic (occupation) - Copy.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
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from statsmodels.graphics.mosaicplot import mosaic
#read used columns
df = pd.read_csv (r'project_data.csv', usecols=[6,9,11,13,14,15])
#draw pie chart for occupation
#print(df['occupation'].value_counts())
query = df[['occupation', 'class', 'sex']].groupby(['occupation', 'class']).count()
query = df[['occupation', 'class']].groupby(['occupation', 'class']).size().reset_index(name='counts')
#print(df[['occupation', 'class']].groupby(['occupation', 'class']).size().reset_index(name='counts'))
labels = query['occupation'].unique()
class1 = query.loc[(query['class'] == 1)]['counts'].tolist()
class2 = query.loc[(query['class'] == 0)]['counts'].tolist()
mosaic(df, ['occupation','income'], title='Occupation', label_rotation=60)
plt.xticks(rotation=60)
plt.show()
#print(df[(df['class'] == 0) & (df['occupation'] != 0)].count())
#plt.pie(df['occupation'].value_counts(), labels=df['occupation'].unique(), shadow=False, autopct='%1.2f%%')
#plt.axis('equal')
#plt.show()
#print(df['class'])