I'm working on a project for a certification from IBM in data science. I'm trying to figure out how to analyze some data in a dataframe using python 3. Basically, I have a df called NY311_df
, and it consists of about 15 columns. The two columns I care about right now are, boroughs
and complaint_type
. Both of these values are strings.
I've tried counting the amount of times each even occurs in the complaint_type
column through a loop, which I will post below, however I keep receiving a syntax error. I found the code to a similar issue here on stackoverflow and tried to modify it. It's saying that my column, complaint_type
, is not defined. Which I don't understand why it can't take the values associated with that column. I'm not really sure where to go from here. Even if this loop runs, that still doesn't solve my issue of associating this with each corresponding borough.
for i in range(0 , NY311_df.shape[1]):
counts = NY311_df.iloc[:,i].value_counts()
gen = (f'{complaint_type} occurs {value} times' for key, value in counts.items())
print(*gen, sep=', ')
I want to find a way to return the amount of times a complaint_type
returned for each borough.
Example output:
"Brooklyn" " Heat: 3, Water: 5, Electric: 6 "
and then it would move on to the next borough --
"Brooklyn" " Heat: 3, Water: 5, Electric: 6 "
"Queens" " Heat: 2, Water: 5, etc..."