-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: scatter plot with categorical data raises KeyError #16199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@jorisvandenbossche Seems like a simple fix that would check the types of x and y at https://github.com/pandas-dev/pandas/blob/master/pandas/plotting/_core.py#L831? |
@stangirala it may have to be earlier, somewhere around https://github.com/pandas-dev/pandas/blob/master/pandas/plotting/_core.py#L335 The issue is we drop non-numeric columns fairly early on, and by the type you get to https://github.com/pandas-dev/pandas/blob/master/pandas/plotting/_core.py#L831, the The cleanest way might be to modify |
@TomAugspurger I see. But it looks like PlanePlot has checks on x and y and not MPLPlot, https://github.com/pandas-dev/pandas/blob/master/pandas/plotting/_core.py#L770. The error in the code sample above passes the check in MPLPlot at https://github.com/pandas-dev/pandas/blob/master/pandas/plotting/_core.py#L335 because x is numeric. So the check would go in PlanePlot right? |
@stangirala Another interesting area to contribute, however a much bigger issue, is to actually better support categorical data (as the above example could work) |
@jorisvandenbossche Maybe you can open a new issue for it? :D It seems like we would have a flag for most plots that would wholesale convert categorical data to a label-to-integer mapping? But I don't think it would make much sense for a scatter plot that requires an inherent ordering. But having equivalent categorical plots is a good idea, for example parallel_sets, #12341 |
Appropriately handles categorical data for dataframe scatter plots which currently raises KeyError for categorical data
Appropriately handles categorical data for dataframe scatter plots which currently raises KeyError for categorical data
Appropriately handles categorical data for dataframe scatter plots which currently raises KeyError for categorical data
There are already some issues about it, eg #12341
Do you mean you think it won't make sense for a scatter plot to support categorical data? I think it could make sense, where you basically use the underlying codes of the categorical as the values to plot |
Oh I meant would someone want a scatter plot for categorical data when most of the times the categories don't have an ordering? I mean in such case won't someone want to use a box plot for example assuming y data is numeric and x is categorical? |
supporting categorical in |
@TomAugspurger I see, a dot plot would make sense. I don't see an issue for this, do I open one? |
We can use #9069 I think.
…On Wed, May 3, 2017 at 5:02 PM, Telt ***@***.***> wrote:
@TomAugspurger <https://github.com/TomAugspurger> I see, a dot plot would
make sense. I don't see an issue for this, do I open one?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#16199 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABQHIkbxYqXIAYLgvVh-FqcdrW-KJNaGks5r2PmTgaJpZM4NOVTt>
.
|
Appropriately handles categorical data for dataframe scatter plots which currently raises KeyError for categorical data
…ev#16208) * BUG: Categorical scatter plot has KeyError pandas-dev#16199 Appropriately handles categorical data for dataframe scatter plots which currently raises KeyError for categorical data * Add to whatsnew (cherry picked from commit 11d274f)
raises
KeyError: 'y'
, while the column certainly exists, which can be very confusing.Without the scatter (just
df.plot(x='x', y='y')
), it raises the more informativeTypeError: Empty 'DataFrame': no numeric data to plot
The text was updated successfully, but these errors were encountered: