I\'ve got pandas DataFrame
, df
, with index
named date
and the columns columnA
, columnB
and
A more simple solution would be:
df['x1'] = df.index
df.plot(kind='scatter', x='x1', y='columnA')
Just create the index variable outside of the plot statement.
This is kind of ugly (I think the matplotlib solution you used in your question is better, FWIW), but you can always create a temporary DataFrame with the index as a column usinng
df.reset_index()
If the index was nameless, the default name will be 'index'
. Assuming this is the case, you could use
df.reset_index().plot(kind='scatter', x='index', y='columnA')