Skip to content

Instantly share code, notes, and snippets.

@cavedave
Created April 27, 2018 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cavedave/38aadc77216efb7316ff12b006297813 to your computer and use it in GitHub Desktop.
Save cavedave/38aadc77216efb7316ff12b006297813 to your computer and use it in GitHub Desktop.
What is the relationship between the % of people in a country who are middle class and the countries democracy score?
import csv
import string
import pandas as pd
import numpy as np
import nltk
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
import scipy.stats as stats
#df = pd.DataFrame()
df = pd.read_csv('middleclass.csv')
#df.to_csv('middleclass.csv')
df.head()
plt.scatter(df.Score, df.Middle)
plt.title("Does Democracy need the Middle Class?")
plt.xlabel("Democracy Score")
plt.ylabel("% Middle Class")
plt.text(2.69, 58.7, 'UAE', horizontalalignment='center',verticalalignment='center')
plt.text(7.7, 1.9, 'India', horizontalalignment='center',verticalalignment='center')
plt.text(7.98, 35, 'USA', horizontalalignment='center',verticalalignment='center')
plt.text(8.53, 54.5, 'UK', horizontalalignment='center',verticalalignment='center')
plt.text(2.93, 32, 'Saudi Arabia', horizontalalignment='center',verticalalignment='center')
plt.text(9, 64, 'Australia', horizontalalignment='center',verticalalignment='center')
plt.text(9.75, 54, 'Norway', horizontalalignment='center',verticalalignment='center')
plt.show()
print(stats.pearsonr(df.Score, df.Middle))
plt.savefig('MiddleClass.png')
Country Score Middle
Argentina 6.96 4
Australia 9.09 66.1
Austria 8.42 44
Belgium 7.78 62.1
Brazil 6.86 8.1
Canada 9.15 47.8
Chile 7.84 22.3
China 3.1 10.7
Colombia 6.67 15.3
Czech Republic 7.62 26.5
Denmark 9.22 39.5
Egypt 3.36 5
Finland 9.03 45.6
France 7.8 49.2
Germany 8.61 42.4
Greece 7.29 47.2
Hong Kong 6.31 44.4
India 7.23 3
Indonesia 6.39 4.4
Ireland 9.15 50.3
Israel 7.79 42.5
Italy 7.98 59.7
Japan 7.88 59.5
South Korea 8 44.6
Malaysia 6.54 16.7
Mexico 6.41 17.1
Netherlands 8.89 54.1
New Zealand 9.26 50.3
Norway 9.87 56.4
Peru 6.49 10.3
Philippines 6.71 4.8
Poland 6.67 19.3
Portugal 7.84 44.6
Russia 3.17 4.1
Saudi Arabia 1.93 33.1
Singapore 6.32 62.3
South Africa 7.24 13.7
Spain 8.08 55.8
Sweden 9.39 39.4
Switzerland 9.03 44.5
Taiwan 7.73 59.4
Thailand 4.63 3.7
Turkey 4.88 9.9
United Arab Emirates 2.69 56.4
United Kingdom 8.53 57.4
United States 7.98 37.7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment