Search code examples
pythonpandasgroup-by

Sum value_count() output


image showing output from below code

homes_by_state = df_south.groupby(["state"])["property_type"].value_counts()

I want to output only "state" and total number of "property_type"


Solution

  • I tried this code homes_by_state = df_south.groupby(["state"])["property_type"].count() and it seems to have done the trick. value_counts() was outputting total for unique values in the column property_type. See snapshot correct output