1

A great feature supported by Pandas is the data.hist(). The hist function allows me to visualize the distribution of numerical values. However, that being said: it only allows me to view the distribution for numerical variables.

If I wanted to view the distribution of categorical variables, I'd need to run select_dtypes in a for loop as follows:

import matplotlib.pyplot as plt

for col in tips.select_dtypes(include=["category"]):
    tips[col].value_counts().plot(kind='bar')
    plt.show()

Is there an easier (more Pythonic) way to view the distribution of categorical variables.

4
  • Take a look at stanford.edu/~mwaskom/software/seaborn/tutorial/… Commented Mar 30, 2016 at 17:07
  • Thanks Stefan, I am familiar with Seaborn - but I'd love to stick with the pandas ecosystem. Commented Mar 30, 2016 at 17:08
  • @Phil it would probably help if you explained why "absolutely not". Assuming that you meant that the duplicate doesn't apply. The accepted answer seems to do the same thing you're doing in the loop. Commented Apr 6, 2016 at 19:32
  • I have a solution at stackoverflow.com/a/54266570/5084355 Commented Jan 19, 2019 at 11:26

0