Reputation: 21
I was trying to do a scatter plot. I was trying with the next code
df = pd.DataFrame({'$a':[1,2], '$b': [10,20]})
df.columns = ['a', 'b']
df
df.plot.scatter(df['a'], df['b'])
I get the error
KeyError: '[1 2] not in index'
Any idea why this happens?
Upvotes: 2
Views: 3151
Reputation: 61
This line is redundant:
df.plot.scatter(df['a'], df['b'])
Since you've already called df
, you only need to refer to the column heading, like so:
df.plot.scatter('a', 'b')
Upvotes: 3
Reputation: 862651
First no problem you are new in python ;)
Need parameter x
and y
in DataFrame.plot.scatter
:
df = pd.DataFrame({'$a':[1,2], '$b': [10,20]})
df.columns = ['a', 'b']
df.plot.scatter(x = 'a', y='b')
Upvotes: 1