2

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?

0

2 Answers 2

3

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')
Sign up to request clarification or add additional context in comments.

Comments

1

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')

graph

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.