Jupyter notebook tensorflow pandas plotting error

Viewed 91

i tried to concat 2 data frame, first one is X as number from 1 to 112

x_data = np.arange(1,113,1)
x_df = pd.DataFrame(data=x_data,columns = ['X'])

the second one is gold price from 2 may until 2 october from : https://drive.google.com/file/d/1tFDgfIJof03vA0VGiqgRsDBZsOdmec2g/view?usp=sharing

after i concat it using

my_data = pd.concat([x_df,emas_df],axis=1)

the data look like this concat of x_df and emas_df

i would like to plot 50 sample from my_data and scatter it with "X" as x, and "Terakhir" (meaning last price in my language) as y using

my_data.sample(n=50).plot(kind='scatter',x='X',y='Terakhir')

i get an error of

ValueError                                Traceback (most recent call last)
<ipython-input-71-ca1cd423cab6> in <module>
----> 1 my_data.sample(n=50).plot(kind='scatter',x='X',y='Terakhir')

c:\users\tila\anaconda3\envs\tfdeeplearning\lib\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 

c:\users\tila\anaconda3\envs\tfdeeplearning\lib\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 

c:\users\tila\anaconda3\envs\tfdeeplearning\lib\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"

c:\users\tila\anaconda3\envs\tfdeeplearning\lib\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]

c:\users\tila\anaconda3\envs\tfdeeplearning\lib\site-packages\pandas\plotting\_core.py in __init__(self, data, x, y, **kwargs)
    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')
    788 
    789         self.x = x

ValueError: scatter requires y column to be numeric

what do i need to do in order to be able to scatter X and Y with respective columns?

1 Answers

The "Terakhir" Series is of string data type and having a comma in each of it.

enter image description here

Do the following to remove comma and convert it into numeric data type:

enter image description here

Finally, Plot it!

enter image description here

Related