0

I am trying to understand why I am getting empty axes for data that is not in an indexed dataframe. I am loading a dataframe, then indexing to only include data where the 'day' column is either 'Thur' or 'Fri', but for some reason when using that indexed dataframe I still get empty axes for 'Sat' and 'Sun'. How does seaborn/relplot even know about those values when I thought they would be non-existent in the dataframe that I passed into relplot?

Executing the below code

import seaborn as sns
tips = sns.load_dataset('tips')
dataSubset=tips[tips['day'].isin(['Thur', 'Fri'])]
g = sns.relplot(x="total_bill", y="tip", row='day', data=dataSubset, facet_kws={'margin_titles': True}, height=2, aspect=1.5)

Produces
Output Figure

I don't understand why there are empty axes for 'Sat' & 'Sun' or where in the dataframe those entries are still registered. Any insight would be appreciated.

Versions

  • Python - 3.9.5
  • Seaborn - 0.11.2
  • Pandas - 1.2.5
BigBen
  • 46,229
  • 7
  • 24
  • 40
Thurbs
  • 3
  • 1

1 Answers1

0

As user BigBen hints in the comments, the day column is a category dtype and subsetting does not remove unused categories. The following addition will fix:

dataSubset['day'] = dataSubset.day.cat.remove_unused_categories()
Derek Croote
  • 106
  • 1
  • 3