Pandas: Exception when building two data frames on the same chart

I have two Pandas DataFrames that I am trying to build on the same chart.

  • all_data: you need to build it like a line graph
  • points_of_interest: you need to build this as a scatter plot on one plot

Here is the code I use to build them:

axes = all_data[ASK_PRICE].plot(figsize=(16, 12)) points_of_interest[ASK_PRICE].plot(figsize=(16, 12), ax = axes, kind='scatter') pylab.show() 

When I run this code, it says:

 >>> points_of_interest[ASK_PRICE].plot(figsize=(16, 12), ax = axes, kind='scatter') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/shubham/.local/lib/python2.7/site-packages/pandas/tools/plotting.py", line 3599, in __call__ **kwds) File "/home/shubham/.local/lib/python2.7/site-packages/pandas/tools/plotting.py", line 2673, in plot_series **kwds) File "/home/shubham/.local/lib/python2.7/site-packages/pandas/tools/plotting.py", line 2430, in _plot % kind) ValueError: plot kind 'scatter' can only be used for data frames 

I confirmed that both data files are of type "DataFrame". What am I missing?

+5
source share
1 answer

you are trying to use pd.Series points_of_interest[ASK_PRICE] with plot(kind='scatter') . You suggested that, naturally, it will take an index against values. Unfortunately, this is not the case.

try it

 axes = all_data[ASK_PRICE].plot(figsize=(16, 12)) poi = points_of_interest[ASK_PRICE] poi.reset_index().plot.scatter(0, 1, ax=axes) pylab.show() 
+1
source

Source: https://habr.com/ru/post/1258611/


All Articles