Skip to content
Advertisement

Remove by column in pandas.DataFrame.hist

After specifying grouping by column a and restricting to column f and g for histogram, I still have column a showing up in green. Is there a way to remove it without going into matplotlib or for loop?

JavaScript

Advertisement

Answer

This is clearly a bug with the pandas library. The problem seems to arise when by is a numeric dtype column — it probably subsets the DataFrame to the labels in column and by and then plots that, which is problematic when by is numeric.

You can either create non-numeric labels for the column that defines your 'by', or if you don’t want to change your data, it suffices to re-assign the type to object just before the plot.

Sample Data

JavaScript

JavaScript

enter image description here

JavaScript

enter image description here

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement