Below are the columns in the DataFrame of data I am iterating on,
> incident_id int64 date > object state object city_or_county > object address object n_killed > int64 n_injured int64 incident_url > object source_url object > incident_url_fields_missing bool congressional_district > float64 gun_stolen object gun_type > object incident_characteristics object latitude > float64 location_description object longitude > float64 n_guns_involved float64 notes > object participant_age object participant_age_group > object participant_gender object participant_name > object participant_relationship object participant_status > object participant_type object sources > object state_house_district float64 state_senate_district > float64 dtype: object
and below is the code i have written,
def count_entries(df,col_name):
""" Return a dictionary with counts of occurrences as value for each key"""
cols_count = {}
col = df[col_name]
for entry in col:
if entry in cols_count.keys():
cols_count[entry] += 1
else:
cols_count = 1
return cols_count
result = count_entries(data, 'gun_stolen')
print (result)
cols_count = 1?