Search code examples
seaborncategorical-data

How to remove a specific value from a countplot?


I have a table with a lot of missing values, which I have to mark as "No Information". In the countplot however, I don´t want to show a "No Information" bar as it distorts all countplots and the heatmap as most values are "No Information".

Does anybody how to remove the "No Information" bars from countplot and sns.heatmap?

Thank you!


Solution

  • With a dataframe df having a column mydata containing rows with text "No Information", you can remove the rows while passing the data argument to the countplot method like this:

    sns.countplot(x="mydata", data=df[-(df.mydata == 'No Information')])
    

    This will plot only those rows which do not have 'No Information' text in them.