I'm working on Chicago crimes dataset and having trouble with the Arrest column. It says True or False but those are strings, not boolean entries. I tried several things I found on this website but it hasn't fixed it.
test = test['Arrest'].map({'False':False, 'True':True})
This just made everything in the dataset True across all columns.
I also tried a for loop though I'm not sure I got it right.
for i in test['Arrest']:
if i=='True':
return 1
else:
return 0
I also found a suggestion for a similar problem. This was the code suggested
def str_to_bool(s):
if s == 'True':
return True
elif s == 'False':
return False
else:
raise ValueError
But I find that very confusing and not quite applicable either
So for a minimal working example, I'm not sure how I'm supposed to present it:
crimes2012 = pd.read_csv("C:\\Users\\Owner\\Desktop\\Chicago Dataset\\Chicago_Crimes_2012_to_2017.csv", header=0)
primary = crimes2012[['Primary Type','Arrest']].copy()
test=primary.groupby(['Primary Type','Arrest']).size().sort_values().reset_index(name='Count')
test['Arrest'] = test.Arrest.map(pd.eval)