Brajesh Kumar Sethi
Brajesh Kumar Sethi

Reputation: 9

pandas datareader should get stock market data but returns error

Here is the code:

import pandas as pd
import pandas_datareader.data as web
import matplotlib.pyplot as plt

start_date = "2020-01-01"
end_date = "2020-12-31"

data = web.DataReader(name="TSLA", data_source='yahoo', start=start_date, end=end_date)
print(data)

close = data['Close']
ax = close.plot(title='Tesla')
ax.set_xlabel('Date')
ax.set_ylabel('Close')
ax.grid()
plt.show()

And this is the error that it returns:

File "F:\anaconda\lib\site-packages\pandas\core\tools\datetimes.py", line 403, in _convert_listlike_datetimes
    arg, _ = maybe_convert_dtype(arg, copy=False, tz=timezones.maybe_get_tz(tz))

TypeError: maybe_convert_dtype() got an unexpected keyword argument 'tz'

It should display a graph of the stock.

Upvotes: 0

Views: 1024

Answers (1)

Change your code to:

import locale
import numpy as np
import pandas as pd
from pandas_datareader import data as wb
import yfinance as yf
yf.pdr_override()


start_date = "2020-01-01"
end_date = "2020-12-31"
ticker = 'TSLA'
data = pdr.get_data_yahoo(ticker,start=start_date, end=end_date)
print(data)

close = data['Close']
ax = close.plot(title='Tesla')
ax.set_xlabel('Date')
ax.set_ylabel('Close')
ax.grid()
plt.show()

to get enter image description here

Upvotes: 1

Related Questions