Scatter requires x column to be numeric
See original GitHub issueIn [30]: df = pd.DataFrame(dict(a=['A', 'B', 'C'], b=[2, 3, 4]))
In [31]: plt.scatter(df['a'], df['b'])
Out[31]: <matplotlib.collections.PathCollection at 0x7f17e17b41d0>
This works, and produces this:
On the other hand, this doesn’t:
In [32]: df.plot.scatter(x='a', y='b')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/data/documents/uni/phd/projects/FluxnetTrafficLights/scripts/plots/predictability_plots.py in <module>()
----> 1 df.plot.scatter(x='a', y='b')
~/miniconda3/envs/science/lib/python3.6/site-packages/pandas/plotting/_core.py in scatter(self, x, y, s, c, **kwds)
2803 axes : matplotlib.AxesSubplot or np.array of them
2804 """
-> 2805 return self(kind='scatter', x=x, y=y, c=c, s=s, **kwds)
2806
2807 def hexbin(self, x, y, C=None, reduce_C_function=None, gridsize=None,
~/miniconda3/envs/science/lib/python3.6/site-packages/pandas/plotting/_core.py in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
2625 fontsize=fontsize, colormap=colormap, table=table,
2626 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 2627 sort_columns=sort_columns, **kwds)
2628 __call__.__doc__ = plot_frame.__doc__
2629
~/miniconda3/envs/science/lib/python3.6/site-packages/pandas/plotting/_core.py in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
1867 yerr=yerr, xerr=xerr,
1868 secondary_y=secondary_y, sort_columns=sort_columns,
-> 1869 **kwds)
1870
1871
~/miniconda3/envs/science/lib/python3.6/site-packages/pandas/plotting/_core.py in _plot(data, x, y, subplots, ax, kind, **kwds)
1650 if isinstance(data, DataFrame):
1651 plot_obj = klass(data, x=x, y=y, subplots=subplots, ax=ax,
-> 1652 kind=kind, **kwds)
1653 else:
1654 raise ValueError("plot kind %r can only be used for data frames"
~/miniconda3/envs/science/lib/python3.6/site-packages/pandas/plotting/_core.py in __init__(self, data, x, y, s, c, **kwargs)
808 # the handling of this argument later
809 s = 20
--> 810 super(ScatterPlot, self).__init__(data, x, y, s=s, **kwargs)
811 if is_integer(c) and not self.data.columns.holds_integer():
812 c = self.data.columns[c]
~/miniconda3/envs/science/lib/python3.6/site-packages/pandas/plotting/_core.py in __init__(self, data, x, y, **kwargs)
783 y = self.data.columns[y]
784 if len(self.data[x]._get_numeric_data()) == 0:
--> 785 raise ValueError(self._kind + ' requires x column to be numeric')
786 if len(self.data[y]._get_numeric_data()) == 0:
787 raise ValueError(self._kind + ' requires y column to be numeric')
ValueError: scatter requires x column to be numeric
Why does pandas require x to be numeric if matplotlib doesn’t?
using versions from conda, on Kubuntu 17.10:
matplotlib 2.1.0 py36hba5de38_0
pandas 0.20.3 py36_0
python 3.6.3 h0ef2715_3
Issue Analytics
- State:
- Created 6 years ago
- Reactions:10
- Comments:17 (5 by maintainers)
Top Results From Across the Web
ValueError: scatter requires x column to be numeric
How are we supposed to run your code? · I have a dictionary named Epvv and plot_data & merged_df are the dataframes in...
Read more >Visualization — pandas 0.19.0 documentation
Scatter plot can be drawn by using the DataFrame.plot.scatter() method. Scatter plot requires numeric columns for x and y axis. These can be...
Read more >Python:ValueError: scatter requires y column to be numeric?
But the error I get is ValueError: scatter requires y column to be numeric. I have not shown the code for plotting the...
Read more >How to Fix in Pandas: TypeError: no numeric data to plot
This error typically occurs when you think a certain column in the DataFrame is numeric but it turns out to be a different...
Read more >scatter requires x column to be numeric이 뜨는데 어떤 게 잘못 ...
%matplotlib inline import pandas as pd df = pd.read_csv('data/movie_metadata.csv') iqr = df['budget'].quantile(0.75) ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have the same error and it occurs only when there is a column of type
DateTime
which is not even selected for the scatter plot.I am also getting a same error
ValueError: scatter requires x column to be numeric
when I am trying plot a column which is ofdatetime
type…how to resolve this @naught101 @ckaldemeyer @sinhrks @bobhaffner @jadolfbr