Vicrobot
Vicrobot

Reputation: 3988

KeyError: "None of [Float64Index([34.62365962451697, 30.28671076822607, 35.84740876993872], dtype='float64')] are in the [columns]"

This is my dataframe:

          x1         x2  y  x2_modified
0  34.623660  78.024693  0    99.294362
1  30.286711  43.894998  0   110.085855
2  35.847409  72.902198  0    96.249345

When i try to access the column x1, it does it perfectly:

>>> print(df.x1)
0    34.623660
1    30.286711
2    35.847409
Name: x1, dtype: float64

But when i try to plot it,

df.plot(x = df.x1, y = df.x2_modified)

It gives above error:

KeyError: "None of [Float64Index([34.62366, 30.286710999999997, 35.847409000000006], dtype='float64')] are in the [columns]"

I'm not getting the reason, please help. Thanks.

Upvotes: 1

Views: 5166

Answers (1)

jezrael
jezrael

Reputation: 862641

If want use DataFrame.plot only pass columns names:

df.plot(x = 'x1', y = 'x2_modified')

If want use matplotlib.pyplot.plot then you can pass Series:

plt.plot(df.x1, df.x2_modified)

Upvotes: 3

Related Questions