I am trying to use yahoo finance for importing stock data I am using the code:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('whitegrid')
plt.style.use("fivethirtyeight")
%matplotlib inline
# For reading stock data from yahoo
from pandas_datareader.data import DataReader
# For time stamps
from datetime import datetime
It is running fine.
from pandas_datareader import data as pdr
import yfinance as yf
yf.pdr_override() # <== that's all it takes :-)
# download dataframe
# The tech stocks we'll use for this analysis
tech_list = ['WIPRO.BO', 'INFY.BO', 'TCS.BO', 'HAPPSTMNDS.BO']
# Set up End and Start times for data grab
end = datetime.now()
start = datetime(end.year - 1, end.month, end.day)
#For loop for grabing yahoo finance data and setting as a dataframe
for stock in tech_list:
# Set DataFrame as the Stock Ticker
globals()[stock] = pdr.get_data_yahoo(stock, start, end)
While running below mentioned code I am getting an error:
company_list = ['WIPRO.BO', 'INFY.BO', 'TCS.BO', 'HAPPSTMNDS.BO']
company_name = ["Wipro", "Infosys", "Tata_Consultancy_Services", "Happiest_Minds_Technologies"]
for company, com_name in zip(company_list, company_name):
company["company_name"] = com_name
df = pd.concat(company_list, axis=0)
df.tail(10)
Error Message:
TypeError Traceback (most recent call last)
<ipython-input-6-4753fcd8a7a3> in <module>
3
4 for company, com_name in zip(company_list, company_name):
----> 5 company["company_name"] = com_name
6
7 df = pd.concat(company_list, axis=0)
TypeError: 'str' object does not support item assignment
Please help me in solving this.
Thanks a lot ^_^
ARIMA is used for forecasting univariate time-series data. Not sure which feature you want to forecast. Came up with this one below:(Upvote if it works for you!)
#For loop for grabing yahoo finance data and setting as a dataframe
lt=[]
for stock in tech_list:
# Set DataFrame as the Stock Ticker
temp_df = pdr.get_data_yahoo(stock, start, end)
temp_df = temp_df.reset_index()
lt.append(temp_df)
# Each element in the list is a DataFrame
df = pd.concat([lt[0],lt[1],lt[2],lt[3]], axis=0)
df = df.reset_index(drop=True)
print(df.head())
Output:
Date Open High Low Close Adj Close Volume
0 2020-07-09 224.850006 224.850006 219.800003 221.600006 221.103027 198245
1 2020-07-10 221.600006 223.449997 219.449997 222.000000 221.502121 109461
2 2020-07-13 224.000000 229.000000 222.750000 227.550003 227.039673 385205
3 2020-07-14 229.000000 231.600006 224.199997 225.050003 224.545288 449975
4 2020-07-15 237.000000 265.500000 233.800003 262.950012 262.360291 6313161