Home > Mobile >  How to drop the row index from plot in pandas
How to drop the row index from plot in pandas

Time:01-26

I am trying to plot my pandas dataframe, which contains 2 columns and 120 rows. I would like the first column of my data to take the x-axis and the second one to be the y-axis. However, when I attempt to plot it using plt.plot, the pandas default row index is getting plotted as the x-axis, and the two columns are plotted as two distinct plots along the y-axis. Below is a screenshot of my dataframe and the resulting plot. How can I plot only my data and not the row indices created by pandas?

Output Code

CodePudding user response:

Define the x and y:

df.plot(x='Base.Time (s)', y='WE(1).Current (A)')

Or, define your time as index:

df.set_index('Base.Time (s)').plot()
  • Related