The datasets which are to be used in this screen.

  1. Age-Group
  2. First-time members
  3. Occupation
  4. Per State we represent
  5. Party-Wise composition

We use the same graphs as that in the PDF

Here onwards we start dealing with the data

use pandas DataFrames


In [2]:
import os
os.chdir("/home/archimedeas/wrkspc/anaconda/major_1/datasets/1_the_senate_datasets")

In [ ]:
import pandas as pd
import numpy as np
from bokeh._legacy_charts import output_notebook, show
import bokeh

df = pd.read_csv("1_age_group_5yr_span.csv", index_col = 0)
df

In [ ]:
df.shape

Style sheet for Matplotlib


In [ ]:
%matplotlib inline
import matplotlib.pyplot as plt
plt.style.use('ggplot')
plt.rcParams['figure.figsize'] = (10.0, 8.0)

Sample Bar Plot


In [ ]:
import numpy as np
import matplotlib.pyplot as plt

N = 5
menMeans = (20, 35, 30, 35, 27)
menStd = (2, 3, 4, 1, 2)

ind = np.arange(N)  # the x locations for the groups
width = 0.35       # the width of the bars

fig, ax = plt.subplots()

rects1 = ax.bar(ind, menMeans, width, color = 'red', alpha = 0.6)

womenMeans = (25, 32, 34, 20, 25)
womenStd = (3, 5, 2, 3, 3)

rects2 = ax.bar(ind + width, womenMeans, width )

# add some text for labels, title and axes ticks
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(ind + width)
ax.set_xticklabels(('Frogs', 'Hogs', 'Bogs', 'Slogs', 'Kerebos'))


ax.legend((rects1[0], rects2[0]), ('Men', 'Women'))

plt.show()

Sample Pie Plot


In [ ]:
import matplotlib.pyplot as plt
import pandas as pd

# The slices will be ordered and plotted counter-clockwise.

labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
sizes = [15, 30, 45, 10]
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']
explode = (0.1, 0.1, 0.1, 0.1) 

plt.pie(sizes, explode=explode, labels=labels, colors=colors,
        autopct='%1.1f%%', shadow=True, startangle=90)
# Set aspect ratio to be equal so that pie is drawn as a circle.
plt.axis('equal')

plt.show()

Average age of Men and Women


In [ ]:
df_men = pd.read_csv("1_age_group_5yr_span.csv")

Now we have read the data from the csv files


In [ ]:
ls_labels_men = []
ls_values_men = []

for i in range(1,df_men.shape[0]):
    ls_labels_men.append(str(df_men.iat[i,0]))
    ls_values_men.append(float(df_men.iat[i,1]))

In [ ]:
import numpy as np
import matplotlib.pyplot as plt

N = len(ls_labels_men)


ind = np.arange(N)  # the x locations for the groups
width = 0.35       # the width of the bars

fig, ax = plt.subplots()

rects1 = ax.bar(ind, ls_values_men, width, color = 'red', alpha = 0.6)



#rects2 = ax.bar(ind + width, ls_values_men, width )

# add some text for labels, title and axes ticks
ax.set_ylabel('Scores')

ax.set_title('Scores by group and gender')
ax.set_xticks(ind + width)
ax.set_xticklabels(ls_labels_men)


#ax.legend((rects1[0], rects2[0]), ('Men', 'Women'))

plt.show()

Producing the same graph for women members


In [ ]:
df_women = pd.read_csv("8_women_age_group.csv")

In [ ]:
ls_labels_women = []
ls_values_women = []

for i in range(1,df_women.shape[0]):
    ls_labels_women.append(str(df_women.iat[i,0]))
    ls_values_women.append(float(df_women.iat[i,1]))

In [ ]:
import numpy as np
import matplotlib.pyplot as plt

N = len(ls_labels_women)


ind = np.arange(N)  # the x locations for the groups
width = 0.35       # the width of the bars

fig, ax = plt.subplots()

#rects1 = ax.bar(ind, ls_values_women, width, color = 'red', alpha = 0.6)



rects2 = ax.bar(ind + width, ls_values_women, width )

# add some text for labels, title and axes ticks
ax.set_ylabel('Scores')

ax.set_title('Scores by group and gender')
ax.set_xticks(ind + width)
ax.set_xticklabels(ls_labels_women)


#ax.legend((rects1[0], rects2[0]), ('Men', 'Women'))

plt.show()

Dealing with Occupational Backgrounds


In [3]:
import pandas as pd
df_men = pd.read_csv("4_educational_background.csv")

In [4]:
df_men


Out[4]:
Table - 4 Educational Background of Members Unnamed: 1 Unnamed: 2
0 Educational Qualifications No. of Members Percentage
1 Under Matriculates/Certified Courses/ Others 17 3.13
2 Matric, Inter/High Secondary, Diploma Holders 92 16.95
3 Under Graduates 15 2.77
4 Graduates includeing those with equivalent tec... 226 41.62
5 Post Graduates including those with equivalent... 160 29.46
6 Doctorate 33 6.07

In [5]:
ls_labels_men = []
ls_values_men = []

for i in range(1,df_men.shape[0]):
    ls_labels_men.append(str(df_men.iat[i,0]))
    ls_values_men.append(float(df_men.iat[i,1]))

In [6]:
len(ls_labels_men)


Out[6]:
6

In [7]:
import matplotlib.pyplot as plt
import pandas as pd
plt.rcParams['figure.figsize'] = (10.0, 10.0)

# The slices will be ordered and plotted counter-clockwise.

labels = ls_labels_men
sizes = ls_values_men
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral', 'red', 'lightgreen']
#explode = (0.1, 0.1, 0.1, 0.1, 0, 0) 

p, text = plt.pie(sizes, labels=labels, colors = colors, shadow=True, startangle=90 )
# Set aspect ratio to be equal so that pie is drawn as a circle.
plt.axis('equal')

#plt.title("Educational Background", fontsize = 50, loc = 'right')

plt.legend(p, labels, loc= 'lower right')

plt.show()

In [ ]: