Home > Mobile >  Get Dataframe out of value_counts calculation
Get Dataframe out of value_counts calculation

Time:06-10

i have schools and classes to analyze % of students succeed exams. If i do so the output is series of multi indexes. But i need a dataframe from this as an output.

df.groupby(["school","class"]).passed_or_not.value_counts.(normalize=True)*100

CodePudding user response:

    df.groupby(["school",
"class"]).passed_or_not.value_counts.(normalize=True)*100.reset_index(name='share')

CodePudding user response:

Maybe try:

(df.groupby(["school","class"])
   .passed_or_not
   .value_counts(normalize=True)*100
   .reset_index())
  • Related