我正在尝试使用yahoo finance导入股票数据我正在使用以下代码:
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
它运转良好。
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)
运行下面提到的代码时,我遇到一个错误:
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)
错误消息:
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
请帮我解决这个问题。
非常感谢^_^
2条答案
按热度按时间wtlkbnrh1#
arima用于预测单变量时间序列数据。不确定要预测的功能。下面是一个例子:(如果对你有效,请向上投票!)
mspsb9vt2#
fix_yahoo_财务包的名称已更改为yfinance。所以请试试这个代码。
get_data_yahoo()方法返回一个 Dataframe 。所以,根据您想要做的事情,您可以生成 Dataframe 列表并将列表连接在一起。