title: How to create a trendline using pandas and matplotlib on financial stock data
body: <p>I am trying to create a trendline on financial stock data using the following code and getting all kinds of errors. Any suggestions are most appreciated.</p>
  
  <pre><code>import pandas as pd
  from pandas_datareader import data
  import numpy as np
  import matplotlib.pyplot as plt
  
  df = data.DataReader(name = "GHC", data_source = "google", start = "2010-01-01", end = "2017-11-01")
  
  #reset the index
  df['ID'] = " "
  df.reset_index(inplace = True)
  df.set_index("ID", inplace = True)
  #print(df.head(10))
  
  #create new df for plotting
  data = df[['Date', 'Close']]
  #print(data.head(10))
  
  #plot stock data
  x = data['Date']
  y = data['Close']
  plt.scatter(x, y)
  
  #create and plot a trendline
  z = np.polyfit(x, y, 1)
  p = np.poly1d(z)
  plt.plot(x, p(x), "r--")
  plt.show()
  </code></pre>