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'
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'