Ali Alhashemi
Ali Alhashemi

Reputation: 33

invalid index to scalar variable seaborn.lmplot

I'm getting this error as I use seaborn.lmplot function to conditionally split the plot into facets.

The output

I'm using the built-in tips dataset.

The table

My code:

sns.lmplot(x='total_bill',y='tip',data=tips,col='day',row='time')

The thing is this happens whenever I choose splitting by the column 'day' but works fine on the others categorical columns.

Upvotes: 0

Views: 1080

Answers (1)

A possible cause of this error is the existence of a category containing a single datapoint. It is then impossible to fit a unique regression line. This indeed seems to be the case here:

tips.groupby(['day', 'time']).agg({'total_bill': 'count'})

Output:

             total_bill
day  time              
Thur Lunch           61
     Dinner           1
Fri  Lunch            7
     Dinner          12
Sat  Dinner          87
Sun  Dinner          76

Upvotes: 3

Related Questions