DrDragon3
DrDragon3

Reputation: 21

Pandas DataReader TypeError

So essentially I have been trying to use the DataReader function but to no avail.

I have imported all the relevant things in my code but everytime I use the DataReader function, I get a TypeError:

import pandas as pd
import pandas_datareader.data as web
import datetime as dt
import yfinance as yf

start_date = dt.datetime(2020, 1, 1)
end_date = dt.datetime(2021, 1, 1)

aapl_df = web.DataReader('AAPL', 'Yahoo', start=start_date, end=end_date)

For this I get this error:TypeError: download() got multiple values for argument 'start'

When I try this code instead:

import pandas_datareader.data as web
import pandas as pd

start_date = pd.to_datetime('2022-01-01')
end_date = pd.to_datetime('2022-06-14')

df = web.DataReader('AAPL', 'yahoo', start_date, end_date)
df.tail(10)

I get the output :

[100%%*] 1 of 1 completed

1 Failed download: ['AAPL']: ValueError("time data 'yahoo' does not match format '%Y-%m-%d'")

Can someone please help?

Upvotes: 2

Views: 264

Answers (2)

Syed Habeeb Ullah Quadri
Syed Habeeb Ullah Quadri

Reputation: 1108

The pandas_datareader library no longer functions with 'yahoo-finance' due to a change in the URL. Therefore, 'yahoo' needs to be removed from the code. The updated code should be as follows:

import pandas as pd
import pandas_datareader.data as web
import datetime as dt
import yfinance as yf
yf.pdr_override()

start_date = dt.datetime(2020, 1, 1)
end_date = dt.datetime(2021, 1, 1)

aapl_df = web.DataReader('AAPL', start=start_date, end=end_date)

Hope this solution works for you.

Upvotes: 0

nisakova
nisakova

Reputation: 622

here, but the yahoo data returning null

from datetime import datetime as dt
import pandas as pd
import pytz
import yfinance as yf

tz = pytz.timezone("America/New_York") 
start_date = tz.localize(dt(2022,1,1))
end_date = tz.localize(dt(2022,6,14))
df = yf.download(['AAPL', 'yahoo'], start=start_date, end=end_date, auto_adjust=True)
df

Upvotes: 1

Related Questions