In [6]:
import json
import numpy as np
import pandas as pd
import datetime
import os
import matplotlib
import matplotlib.pyplot as plt
import seaborn as sns
colours = sns.color_palette()
sns.set_style("white")
sns.set_context("poster")

%matplotlib inline

In [7]:
columns = ['topic1', 'topic2', 'topic3', 'time']

data_df = pd.DataFrame(columns=columns)
data_df.index.name = 'respondent'
data_df


Out[7]:
topic1 topic2 topic3 time
respondent

In [8]:
data_path = './../responses/'
# Deal with question 1

i = 0
for index, file_ in enumerate(os.listdir(data_path)):
    
    if ('second_stage_' in file_):
       
        json_data=open(os.path.join(data_path, file_)).read()
        data = json.loads(json_data)

        for selection in data['choices']:
                        
            data_df.set_value(i, selection['question'].replace(' ', '').lower(), int(selection['selected_id']))
        
        data_df.set_value(i, 'time', datetime.datetime.fromtimestamp(data['time']/1000))
        i += 1

data_df


Out[8]:
topic1 topic2 topic3 time
respondent
0 2 3 2 2017-05-02 09:30:17
1 3 3 3 2017-05-02 09:41:22
2 2 2 3 2017-05-02 09:41:36
3 3 3 3 2017-05-02 10:41:57
4 2 1 3 2017-05-02 12:29:10
5 3 3 3 2017-05-02 13:21:30
6 3 1 1 2017-05-02 14:22:47
7 1 3 1 2017-05-02 14:23:08
8 2 2 1 2017-05-02 14:23:37
9 3 1 3 2017-05-02 14:27:12
10 1 3 2 2017-05-03 13:24:50
11 1 2 3 2017-05-03 21:51:19
12 2 1 3 2017-05-04 03:47:56
13 2 2 3 2017-05-04 08:45:34
14 3 3 1 2017-05-04 09:34:22
15 1 2 2 2017-05-04 15:57:33
16 1 3 3 2017-05-05 11:49:37

In [9]:
vals = [data_df['topic{}'.format(i)].values for i in range(1,4)]

In [11]:
plt.figure(figsize=(5,4))
plt.hist(vals, label=['Topic 1', 'Topic 2', 'Topic 3'], alpha=0.8)
plt.legend(loc='best')
plt.xticks([1.1,2.1,2.9], ['Ranking', 'Cardinal Score', 'Plurality'])
plt.ylabel('count')
plt.show()



In [ ]:


In [ ]:


In [ ]: