2

If I have a data frame, where I want to create a scatter plot of a column against the index, is there a way simpler than using matplotlib directly, or create a list out of the index, etc? Something like this:

df.plot.scatter(x='index', y='price')

I am assuming that this won't work, because an index might consist of multiple series and Pandas won't know which to draw upon, without further indication.

Preslav Rachev
  • 3,983
  • 6
  • 39
  • 63

1 Answers1

9

Temporarily reset the index and treat it just like any other column:

df.reset_index().plot.scatter(x='level_0', y='price')
DYZ
  • 55,249
  • 10
  • 64
  • 93