AttributeError: module 'yfinance' has no attribute 'download'
Question:
I’m trying to import yfinance and some stocks into pandas dataframe. Initially had major issues importing yfinance. I installed using pip but still had to manually put in the files to actually get rid of the no module error.
This is my code so far:
Now I’m getting attribute error when trying to download yfinance.
import pandas as pd
import datetime as dt
import yfinance as yf
# import fix_yahoo_finance as yf
stocks = ["AMZN", "MSFT", "INTC", "GOOG", "INFY.NS", "3988.HK"]
start = dt.datetime.today()- dt.timedelta(30)
end = dt.datetime.today()
cl_price = pd.DataFrame()
for ticker in stocks:
cl_price[ticker] = yf.download(ticker,start,end)["Adj Close"]
and this is the error:
AttributeError Traceback (most recent call last)
<ipython-input-51-3347ed0c7f2b> in <module>
10
11 for ticker in stocks:
---> 12 cl_price[ticker] = yf.download(ticker,start,end)["Adj Close"]
AttributeError: module 'yfinance' has no attribute 'download'
I tried the suggestion from AttributeError: module 'yahoo_finance' has no attribute 'download' but its still not working
Any solutions appreciated
Answers:
I installed using pip but still had to manually put in the files to actually get rid of the no module error.
This could be the likely cause of the error. Manually doing is highly discouraged and it always recommended to install with a package tool. If you are using an anaconda environment, consider installing via conda
and remove your manually placed files.
$ conda install -c ranaroussi yfinance
And also make sure that you satisfy all the requirements
Python >= 2.7, 3.4+,
Pandas (tested to work with >=0.23.1),
Numpy >= 1.11.1,
requests >= 2.14.2
I just been having the same error but the following code worked after deleting a local file named yahoofinance
!pip install yfinance
import yfinance as yf
import pandas as pd
import datetime as dt
This will do what you want.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import scipy.optimize as sco
import datetime as dt
import math
from datetime import datetime, timedelta
from pandas_datareader import data as wb
from sklearn.cluster import KMeans
np.random.seed(777)
start = '2022-09-22'
end = '2022-11-23'
tickers = ['AXP','AMGN','AAPL','BA','CAT','CSCO','CVX','GS','HD','HON','IBM','INTC','JNJ','KO','JPM','MCD','MMM','MRK','MSFT','NKE','PG','TRV','UNH','CRM','VZ','V','WBA','WMT','DIS']
thelen = len(tickers)
price_data = []
for ticker in tickers:
try:
prices = wb.DataReader(ticker, start = start, end = end, data_source='yahoo')[['Adj Close']]
price_data.append(prices.assign(ticker=ticker)[['ticker', 'Adj Close']])
except:
print(ticker)
df = pd.concat(price_data)
df.dtypes
df.tail()
df.shape
pd.set_option('display.max_columns', 500)
pd.set_option('display.max_rows', None)
df = df.reset_index()
df = df.set_index('Date')
table = df.pivot(columns='ticker')
# By specifying col[1] in below list comprehension
# You can select the stock names under multi-level column
table.columns = [col[1] for col in table.columns]
table.head()
I’m trying to import yfinance and some stocks into pandas dataframe. Initially had major issues importing yfinance. I installed using pip but still had to manually put in the files to actually get rid of the no module error.
This is my code so far:
Now I’m getting attribute error when trying to download yfinance.
import pandas as pd
import datetime as dt
import yfinance as yf
# import fix_yahoo_finance as yf
stocks = ["AMZN", "MSFT", "INTC", "GOOG", "INFY.NS", "3988.HK"]
start = dt.datetime.today()- dt.timedelta(30)
end = dt.datetime.today()
cl_price = pd.DataFrame()
for ticker in stocks:
cl_price[ticker] = yf.download(ticker,start,end)["Adj Close"]
and this is the error:
AttributeError Traceback (most recent call last)
<ipython-input-51-3347ed0c7f2b> in <module>
10
11 for ticker in stocks:
---> 12 cl_price[ticker] = yf.download(ticker,start,end)["Adj Close"]
AttributeError: module 'yfinance' has no attribute 'download'
I tried the suggestion from AttributeError: module 'yahoo_finance' has no attribute 'download' but its still not working
Any solutions appreciated
I installed using pip but still had to manually put in the files to actually get rid of the no module error.
This could be the likely cause of the error. Manually doing is highly discouraged and it always recommended to install with a package tool. If you are using an anaconda environment, consider installing via conda
and remove your manually placed files.
$ conda install -c ranaroussi yfinance
And also make sure that you satisfy all the requirements
Python >= 2.7, 3.4+,
Pandas (tested to work with >=0.23.1),
Numpy >= 1.11.1,
requests >= 2.14.2
I just been having the same error but the following code worked after deleting a local file named yahoofinance
!pip install yfinance
import yfinance as yf
import pandas as pd
import datetime as dt
This will do what you want.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import scipy.optimize as sco
import datetime as dt
import math
from datetime import datetime, timedelta
from pandas_datareader import data as wb
from sklearn.cluster import KMeans
np.random.seed(777)
start = '2022-09-22'
end = '2022-11-23'
tickers = ['AXP','AMGN','AAPL','BA','CAT','CSCO','CVX','GS','HD','HON','IBM','INTC','JNJ','KO','JPM','MCD','MMM','MRK','MSFT','NKE','PG','TRV','UNH','CRM','VZ','V','WBA','WMT','DIS']
thelen = len(tickers)
price_data = []
for ticker in tickers:
try:
prices = wb.DataReader(ticker, start = start, end = end, data_source='yahoo')[['Adj Close']]
price_data.append(prices.assign(ticker=ticker)[['ticker', 'Adj Close']])
except:
print(ticker)
df = pd.concat(price_data)
df.dtypes
df.tail()
df.shape
pd.set_option('display.max_columns', 500)
pd.set_option('display.max_rows', None)
df = df.reset_index()
df = df.set_index('Date')
table = df.pivot(columns='ticker')
# By specifying col[1] in below list comprehension
# You can select the stock names under multi-level column
table.columns = [col[1] for col in table.columns]
table.head()