I would like to spcify x and y axis to draw data in dataframe in Python.
For example, I have four columns in dataframe. And here's my code.
df.plot(x=df['a'], y=df['b'], label=df['c'])
It throws an error saying: These values come from 'b' column.
"KeyError: '[ 500.8 567.2 487.2 444.4 1371.6 714.4 1157.4
476.8 345.4\n 1076.4 881.8 813. 452.6 663.6 606.8 469.2 805.2 487.4\n 497.8 440. 127. 68.6 1494.2 716.4 1447. 97.8 110.\n 1126.4 1422.8 92.4 1000.8] not in index'"
Thank you for the help in advance.
You can set the labels on that object. Or, more succinctly: ax. set(xlabel="x label", ylabel="y label") . Alternatively, the index x-axis label is automatically set to the Index name, if it has one.
DataFrame - set_axis() function The set_axis() function is used to assign desired index to given axis. Indexes for column or row labels can be changed by assigning a list-like or Index. The values for the new index. The axis to update.
df.plot takes the column labels as x and y, not the data itself
df.plot(x='a', y='b')
might work
Use https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.plot.html as reference to the arguments needed in pandas
https://pandas.pydata.org/pandas-docs/stable/visualization.html as examples
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With