-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathanalyze_pace_survey.py
55 lines (42 loc) · 1.22 KB
/
analyze_pace_survey.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
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 29 13:44:15 2016
@author: sglyon
"""
#%% Reading data from the internet
import pandas as pd
url1 = "https://raw.githubusercontent.com/NYUDataBootcamp/"
url2 = "Materials/master/Data/fall16_ug_pace.csv"
url = url1 + url2
df = pd.read_csv(url, index_col=0)
#%% Dataframe properties
print("The columns in this dataframe are:")
print(df.columns.tolist())
#%%
print("The size of this DataFrame is (# rows, # columns)")
print(df.shape)
# save number of rows and columns
n_response, n_columns = df.shape
#%% Accesing a variable
# get pace variable, save it as a new variable
pace = df["pace"]
# get all variables for subjects
subject_cols = list(range(3, n_columns))
subjects = df[subject_cols]
#%% DataFrame methods
# number of people who requested a review of each topic
subjects.sum()
# bar plot of the sum
subject_totals = subjects.sum()
subject_totals.plot(kind="barh")
#%% loops
# Iterate over all responses
for i in range(n_response):
print("This is response", i)
# Iterate over all questions
print("Person", i, "asked to cover")
for question in df.columns:
if question in subjects:
if df[question][i] == True:
print(" ", question)
#%%