Created
January 15, 2016 04:43
-
-
Save tpatch/302484722dff8fe00a73 to your computer and use it in GitHub Desktop.
Python Data Script for Coursera
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas | |
import numpy | |
pandas.set_option('display.float_format', lambda x: '%f'%x) | |
data = pandas.read_csv('datasets/ool_pds.csv', low_memory=False) | |
data.columns = map(str.upper, data.columns) | |
print(len(data)) | |
print(len(data.columns)) | |
# | |
data["W1_A11"] = data["W1_A11"].convert_objects(convert_numeric=True) | |
data["W1_K1_B"] = data["W1_K1_B"].convert_objects(convert_numeric=True) | |
data["W1_K1_A"] = data["W1_K1_A"].convert_objects(convert_numeric=True) | |
data["W1_K1_C"] = data["W1_K1_C"].convert_objects(convert_numeric=True) | |
data["W1_K1_D"] = data["W1_K1_D"].convert_objects(convert_numeric=True) | |
data["W1_B4"] = data["W1_B4"].convert_objects(convert_numeric=True) | |
# Pull and print variables | |
print("In all cases, -1 = Refusal to answer") | |
print("Days of week watching news; 1 = None, 2 = One...., 8 = Seven") | |
news = data["W1_A11"].value_counts(sort=True, normalize=True) | |
print(news) | |
print("Police Trust; 1 = Always, 4 = Never") | |
police = data["W1_K1_B"].value_counts(sort=True, normalize=True) | |
print(police) | |
print("Govt Trust; 1 = Always, 4 = Never") | |
govt = data["W1_K1_A"].value_counts(sort=True, normalize=True) | |
print(govt) | |
print("Legal System Trust; 1 = Always, 4 = Never") | |
lsystem = data["W1_K1_C"].value_counts(sort=True, normalize=True) | |
print(lsystem) | |
print("Public School Trust; 1 = Always, 4 = Never") | |
pschool = data["W1_K1_D"].value_counts(sort=True, normalize=True) | |
print(pschool) | |
print("Anger About Country; 1 = Extremely Angry, 5 = Not Angry at All") | |
anger = data["W1_B4"].value_counts(sort=True, normalize=True) | |
print(anger) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment