Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot graph against index in python [duplicate]

The data looks like this:

        1       2       3       4
foo             
t0      95      95.5    75.5    85
t1      95.75   95.5    75.5    85
t2      96.5    95.5    75.5    85
t3      96.5    95.5    75.5    85
t4      96.5    95.5    75.5    85
...     ...     ...    ...  ...
t9996   95.5    95      75.5    85.5
t9997   95.5    95      75.5    85.5
t9998   95.5    95      75.5    85.5
t9999   95.5    95      75.5    85.5
t10000  95.5    95      75.5    85.5

I want to plot the 4 time series against the index. Using code:

df.plot(x = 'foo', y = '1')

I received this error:

KeyError: 'foo'

How should I do this?

like image 321
nilsinelabore Avatar asked Sep 20 '26 07:09

nilsinelabore


1 Answers

Use this. If x argument isn't provided, DataFrame.plot() takes df.index as default.

df.plot(y='1')
like image 98
Reuben Avatar answered Sep 21 '26 21:09

Reuben



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!