2

I'm trying to plot the values from the A column against the index(Of the DataFrame table), but it doesnt allow me to. How to do it?

INDEX is the index from the DataFrame and not the declared variable.

enter image description here

user234568
  • 741
  • 3
  • 11
  • 21

1 Answers1

0

You need plot column A only, index is used for x and values for y by default in Series.plot:

#line is default method, so omitted
Test['A'].plot(style='o')

Another solution is reset_index for column from index and then DataFrame.plot:

Test.reset_index().plot(x='index', y='A', style='o')

Sample:

Test=pd.DataFrame({'A':[3.0,4,5,10], 'B':[3.0,4,5,9]})
print (Test)
      A    B
0   3.0  3.0
1   4.0  4.0
2   5.0  5.0
3  10.0  9.0

Test['A'].plot(style='o')

graph


print (Test.reset_index())
   index     A    B
0      0   3.0  3.0
1      1   4.0  4.0
2      2   5.0  5.0
3      3  10.0  9.0

Test.reset_index().plot(x='index', y='A', style='o')

graph1

jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
  • Thank you very much for your help. If I want the y-axis to run from 0 to 10, how can I do it? – user234568 Aug 09 '17 at 06:11
  • You need `ax = Test['A'].plot(style='o')` `ax.set_ylim(0,10)` - see [here](https://stackoverflow.com/questions/17787366/setting-yaxis-in-matplotlib-using-pandas) – jezrael Aug 09 '17 at 06:25