Can't plot value counts for pie chart Can't plot value counts for pie chart pandas pandas

Can't plot value counts for pie chart


While value_counts is a Series method, it's easily applied to the Series inside DataFrames by using DataFrame.apply. In your case. for example,

df[variables].apply(pd.value_counts).plot(kind='pie', layout=(n_rows,n_cols), subplots=True)

(assuming pandas has been imported as pd).

For a complete example:

import pandas as pda = pd.DataFrame({'a': [1,0,0,0,1,1,0,0,1,0,1,1,1],'b': [1,0,0,0,1,1,0,0,1,0,0,0,0]})a.apply(pd.value_counts).plot.pie(subplots=True)