小编sir*_*shp的帖子

读取股票数据时出错:“DatetimeProperties”对象没有属性“weekday_name”,“NoneType”对象没有属性“to_csv”

我尝试运行代码来获取股票数据,但失败了,显示以下错误:

'DatetimeProperties' 对象没有属性 'weekday_name'
'NoneType' 对象没有属性 'to_csv'

from pandas_datareader import data as web
import os
import pandas as pd
from pandas.testing import assert_frame_equal
Run Code Online (Sandbox Code Playgroud)
def get_stock(ticker, start_date, end_date, s_window, l_window):
    try:
        df = web.get_data_yahoo(ticker, start=start_date, end=end_date)
        df['Return'] = df['Adj Close'].pct_change()
        df['Return'].fillna(0, inplace = True)
        df['Date'] = df.index
        df['Date'] = pd.to_datetime(df['Date'])
        df['Month'] = df['Date'].dt.month
        df['Year'] = df['Date'].dt.year 
        df['Day'] = df['Date'].dt.day
        for col in ['Open', 'High', 'Low', 'Close', 'Adj Close']:
            df[col] = df[col].round(2)
        df['Weekday'] = df['Date'].dt.weekday_name  
        df['Week_Number'] = df['Date'].dt.strftime('%U')
        df['Year_Week'] = df['Date'].dt.strftime('%Y-%U')
        df['Short_MA'] …
Run Code Online (Sandbox Code Playgroud)

python pandas pandas-datareader

7
推荐指数
2
解决办法
2万
查看次数

标签 统计

pandas ×1

pandas-datareader ×1

python ×1