3

apple is a dataframe whose data structure is as the below:

apple
           Date        Open        High         Low       Close   Adj Close  
0    2017-01-03  115.800003  116.330002  114.760002  116.150002  114.311760   
1    2017-01-04  115.849998  116.510002  115.750000  116.019997  114.183815   
2    2017-01-05  115.919998  116.860001  115.809998  116.610001  114.764473   
3    2017-01-06  116.779999  118.160004  116.470001  117.910004  116.043915   
4    2017-01-09  117.949997  119.430000  117.940002  118.989998  117.106812   
5    2017-01-10  118.769997  119.379997  118.300003  119.110001  117.224907   
6    2017-01-11  118.739998  119.930000  118.599998  119.750000  117.854782   
7    2017-01-12  118.900002  119.300003  118.209999  119.250000  117.362694   
8    2017-01-13  119.110001  119.620003  118.809998  119.040001  117.156021   
9    2017-01-17  118.339996  120.239998  118.220001  120.000000  118.100822 

Now i want to select two columns Date and Close ,to set Date as x axis and Close as y axis,how to plot it?

import pandas as pd    
import matplotlib.pyplot as plt    
x=pd.DataFrame({'key':apple['Date'],'data':apple['Close']})    
x.plot()   
plt.show() 

I got the graph such as below.

enter image description here

The x axis is not Date column !

1 Answer 1

2

New DataFrame is not necessary, plot apple and use parameters x and y:

#if not datetime column first convert
#apple['Date'] = pd.to_datetime(apple['Date'])

apple.plot(x='Date', y='Close')  

graph

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.