letylin / pyprogbook

金融大數據首部曲 書名: Python 程式設計入門 — 金融商管實務案例 讀者可以在此下載教學資源含程式碼
53 stars 28 forks source link

RC_7_1程式出現錯誤 #22

Closed today20050110 closed 6 years ago

today20050110 commented 6 years ago

from pandas_datareader import data as pdr import fix_yahoo_finance as yf import pandas as pd import datetime yf.pdr_override() # <== that's all it takes :-) start = datetime.datetime(2016,4,1) end = datetime.datetime(2016,4,19) df = pdr.get_data_yahoo('2330.tw', start, end) writer=pd.ExcelWriter('D:/pyprogbook-master/ch7file/2330.xlsx') df.to_excel(writer,'2330') workbook=writer.book worksheet=writer.sheets['2330'] chart=workbook.add_chart({'type':'stock'}) chart.add_series({'name':'=2330!$B$1','categories': '=2330!$A$2:$A$14','values':'=2330!$B$2:$B$14'}) chart.add_series({'name':'=2330!$C$1','categories': '=2330!$A$2:$A$14','values':'=2330!$C$2:$C$14'}) chart.add_series({'name':'=2330!$D$1','categories': '=2330!$A$2:$A$14','values':'=2330!$D$2:$D$14'}) chart.set_title({'name':'High-Low-Close'}) chart.set_x_axis({'name':'Date'}) chart.set_y_axis({'name':'Share price'}) worksheet.insert_chart('I2',chart) writer.save()

錯誤訊息如下 File "C:/Users/pc-20160229/PycharmProjects/untitled2/test2.py", line 14, in chart=workbook.add_chart({'type':'stock'}) AttributeError: 'Workbook' object has no attribute 'add_chart'

letylin commented 6 years ago

你好: 請到Code頁面, 下載ch7_fix_yahoo_finance.zip python 官方已於2018年2月修復yahoo finance api.

today20050110 commented 6 years ago

解決了,謝謝老師