Maybe I’m missing something but doesn’t this work for you?
agg = df.groupby('number_of_genres').agg('sum').T
agg['totals'] = agg.sum(axis=1)
Edit: Solution via pivot_table
agg = df.pivot_table(columns="number_of_genres", aggfunc="sum")
agg['total'] = agg.sum(axis=1)
2
solved Pivoting a One-Hot-Encode Dataframe