Matplotlib 3.0 Cookbook
上QQ阅读APP看书,第一时间看更新

How it works...

The following is the explanation of the code:

  • pd.read_csv() function specifies the following:
    • header=None, input file has no header
    • delimiter=',', date and price are separated by a comma (,)
    • Read the data into the stock DataFrame
  • The stock.columns command assigns names for each of the attributes, date and price, within the stock DataFrame. 
  • The pd.to_datetime() function converts the date from the character format to the date time format. The format: %d-%m-%Y argument specifies the format of the date in the input file.
  • stock.set_index() sets the date column as the index, so that the price column can represent the time series data, which is understood by the plot command.

The following graph is the output you should get from the preceding code block: