嘗試使用帶有散景的多張 excel 檔案制作一些繪圖。想要使用 for 回圈,這樣我就不必在每張紙上一遍又一遍地創建資料框。無法讓它作業。以下是代碼:
from math import pi
import pandas as pd
from bokeh.plotting import figure, output_file, show
from bokeh.models import Range1d,LinearAxis
datafile="DataImport.xlsx"
data=pd.ExcelFile(datafile)
sheet_names=data.sheet_names
for sht_name in sheet_names:
df_sht_name=data.parse(sht_name)
df_sht_name=sht_name.iloc[2:,[0,2,3]]
df_sp #sp is one of sheets in the excel file
收到錯誤訊息“NameError: name 'df_sp' is not defined”
uj5u.com熱心網友回復:
@BigBen 字典有效。謝謝。
以下是代碼:
datafile="DataImport.xlsx"
data=pd.ExcelFile(datafile)
sheet_names=data.sheet_names
frames={}
for sht_name in sheet_names:
df_temp=data.parse(sht_name)
df_temp=df_temp.iloc[2:,[0,2,3]]
df_temp.columns=['Date', 'High','Close']
frames[sht_name]=df_temp
#print(frames)
#print(frames['sp'])
p=figure(y_range=(1000,5000),x_axis_type='datetime', sizing_mode = 'stretch_both')
p.circle(frames['sp']['Date'],frames['sp']['Close'], legend_label='Close',color='red',size=3,alpha=0.8)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/456872.html
上一篇:在串列中以五人組申請“for”
