In [12]:
# -*- coding: UTF-8 -*-
# Render our plots inline
%matplotlib inline
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import seaborn
import shutil
import math
pd.set_option('display.mpl_style', 'default') # Make the graphs a bit prettier, overridden by seaborn
pd.set_option('display.max_columns', None) # Display all the columns
plt.rcParams['font.family'] = 'sans-serif' # Sans Serif fonts for all the graphs
# Reference for color palettes: http://web.stanford.edu/~mwaskom/software/seaborn/tutorial/color_palettes.html
# Change the font
matplotlib.rcParams.update({'font.family': 'Source Sans Pro'})
In [2]:
# Load csv file first
data = pd.read_csv("data/results-makers-40.csv", encoding="utf-8")
In [3]:
# Check data
#data[0:4] # Equals to data.head()
In [4]:
# Range: Q021[SQ001] - Q021[SQ005]
skills_columns = ['Q022[SQ001]','Q022[SQ002]','Q022[SQ003]','Q022[SQ004]','Q022[SQ005]']
skills_options = ['Informatica','Elettronica','Progettazione CAD/CAM','Fabbricazione Digitale','Fabbricazione Analogica',]
skills = data[skills_columns]
skills.replace(u'“Guru” (geek)', 'Guru', inplace=True) # Simplify text
skills.replace(np.nan, 'Nessuna risposta', inplace=True) # Simplify text
In [5]:
#skills
In [6]:
%%capture output
# Save the output as a variable that can be saved to a file
# Gather data
skills_b = {}
for k,i in enumerate(skills_columns):
skills_b[k] = skills[i].value_counts()
print "Data:",skills_options[k]
print skills_b[k]
print
print "Data %:",skills_options[k]
print skills[i].value_counts(normalize=True)*100
print
In [7]:
# Save+show the output to a text file
%save Q022-MakerQualiCompetenze.py str(output)
shutil.move("Q022-MakerQualiCompetenze.py", "text/Q022-MakerQualiCompetenze.txt")
In [10]:
nessuno = []
elementare = []
amatoriale = []
professionale = []
guru = []
nanvalue = []
for k,i in enumerate(skills_columns):
skills_presents = skills_b[k].index.tolist()
# Reassign new list with "NaN"
skills_b[k].index = skills_presents
# Check for empty values, and put a 0 instead
if "Nessuno" not in skills_presents:
nessuno.append(0)
if "Elementare" not in skills_presents:
elementare.append(0)
if "Amatoriale" not in skills_presents:
amatoriale.append(0)
if "Professionale" not in skills_presents:
professionale.append(0)
if "Guru" not in skills_presents:
guru.append(0)
if "Nessuna risposta" not in skills_presents:
nanvalue.append(0)
for j in skills_presents:
if j == "Nessuno":
nessuno.append(skills_b[k].ix[j])
elif j == "Elementare":
elementare.append(skills_b[k].ix[j])
elif j == "Amatoriale":
amatoriale.append(skills_b[k].ix[j])
elif j == "Professionale":
professionale.append(skills_b[k].ix[j])
elif j == "Guru":
guru.append(skills_b[k].ix[j])
elif j == "Nessuna risposta":
nanvalue.append(skills_b[k].ix[j])
In [13]:
# Plot the data
plt.figure(figsize=(16,6))
plt.xlabel('Competenze', fontsize=16)
plt.ylabel('Persone', fontsize=16)
plt.title(u'Qual è il livello delle tue competenze tecniche e tecnologiche?', fontsize=18, y=1.02)
plt.xticks(range(len(skills_options)+1),skills_options,rotation=0)
ind = np.arange(len(skills_columns)) # the x locations for the groups
width = 0.15 # the width of the bars
my_colors = seaborn.color_palette("Set1", 6) # Set color palette
rect1 = plt.bar(ind,nessuno,width,color=my_colors[0],align='center') # Plot Nessuno
rect2 = plt.bar(ind+width,elementare,width,color=my_colors[1],align='center') # Plot Elementare
rect3 = plt.bar(ind+width*2,amatoriale,width,color=my_colors[2],align='center') # Plot Amatoriale
rect4 = plt.bar(ind+width*3,professionale,width,color=my_colors[3],align='center') # Plot Professionale
rect5 = plt.bar(ind+width*4,guru,width,color=my_colors[4],align='center') # Plot Guru
rect6 = plt.bar(ind+width*5,nanvalue,width,color=my_colors[5],align='center') # Plot NaN
plt.legend( (rect1, rect2, rect3, rect4, rect5, rect6), ('Nessuno', 'Elementare', 'Amatoriale', 'Professionale', 'Guru', 'NaN') )
plt.savefig("svg/Q022-MakerQualiCompetenze.svg")
plt.savefig("png/Q022-MakerQualiCompetenze.png")
plt.savefig("pdf/Q022-MakerQualiCompetenze.pdf")
In [9]: