In [1]:
import pandas as pd
In [4]:
df = pd.read_csv('suicide_history.csv')
In [5]:
df.head()
Out[5]:
In [6]:
df.columns
Out[6]:
In [ ]:
In [48]:
df.head()
Out[48]:
In [49]:
df['District'].value_counts()['dhaka']
Out[49]:
In [61]:
# Overall death methodologies
unique_methods = list(set(df['Methodology'].str.lower()))
print df['Methodology'].value_counts()
In [101]:
# Methodologies by gender
male_suicide_desc = df[df['Gender'] == 'male']['Methodology'].value_counts()
print sum(male_suicide_desc)
In [96]:
female_suicide_desc = df[df['Gender'] == 'female']['Methodology'].value_counts()
In [92]:
with open('male_suicide.txt', 'w') as f:
f.write('[')
for method in unique_methods:
try:
data_to_write = "{\"gender\" : \"male\", \"method\": \"%s\" , \"count\": %s}" % (method, male_suicide_desc[method])
f.write(data_to_write + ',\n')
except:
print "ERROR"
f.write(']')
f.close()
In [54]:
df_onlineshop = pd.read_csv('Online_shoping_survey_data.csv')
df_onlineshop['Respondents Gender'].str.lower()
df_onlineshop['Respondents Professional Status'].str.lower()
Out[54]:
In [95]:
for method in unique_methods:
try:
print "Method: {} Count: {}".format(method, male_suicide_desc[method])
except:
print "Method: {} Count: {} ".format(method, 0)
In [97]:
for method in unique_methods:
try:
print "Method: {} Count: {}".format(method, female_suicide_desc[method])
except:
print "Method: {} Count: {} ".format(method, 0)
In [103]:
print sum(male_suicide_desc)
In [110]:
with open('male_suicide_data.txt', 'w') as f:
for method in unique_methods:
try:
data_to_write = "{group: \"Male\", category: \"%s\", measure: %s}" % (method, male_suicide_desc[method])
except:
print "EXCEPTION"
data_to_write = "{group: \"Male\", category: \"%s\", measure: %s}" % (method, "0")
f.write(data_to_write + ',\n')
f.close()
In [121]:
df_onlineshop.keys()
for key in df_onlineshop.keys():
try:
df_onlineshop[key] = df_onlineshop[key].str.lower()
except:
print "ERROR"
In [123]:
respondents_professional_status = {
"1": "businessman",
"2": "service Holder",
"3": "home Maker",
"4": "Self Employed",
"5": "Teacher",
"6": "Student",
"7": "Others"
}
In [124]:
respondents_marital_status = {
"1": "Married",
"2": "Unmarried",
"3": None
}
In [125]:
purpose_of_using_internet = {
1: "Shopping",
2: "Work",
3: "Education",
4: "Social Media",
5: "Phone calls or distant messaging",
6: "Others",
7: None
}
In [126]:
df_onlineshop['Respondents Professional Status'].replace(respondents_professional_status, inplace=True)
df_onlineshop['Respondent\'s Marital Status'].replace(respondents_marital_status, inplace=True)
df_onlineshop['Main Purpose of using internet'].replace(purpose_of_using_internet, inplace=True)
In [127]:
df_onlineshop.keys()
for key in df_onlineshop.keys():
try:
df_onlineshop[key] = df_onlineshop[key].str.lower()
except:
print "ERROR"
In [128]:
df_onlineshop.head()
Out[128]:
In [129]:
df_onlineshop.to_csv('output_shopping.csv')
In [1]:
shopping_data = 'malevsfemale.tsv'
In [2]:
import pandas as pd
In [3]:
df = pd.read_csv(shopping_data, sep='\t')
In [6]:
df_male = df[df['Respondents Gender'] == 'male']
In [7]:
df_female = df[df['Respondents Gender'] == 'female']
In [13]:
df_male.head(15)
Out[13]:
In [15]:
df_female.head(df_female.shape[0])
Out[15]:
In [ ]: