无法使用 for 循环从 excel 文件绘制散景中的多张纸
Couldn't plot from an excel file with multiple sheets in bokeh with a for loop
尝试从具有多个 sheet 的 excel 文件制作一些带有散景的图。想要使用 for 循环,这样我就不必为每个 sheet 一遍又一遍地创建数据帧。无法正常工作。以下是代码:
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:名称 'df_sp' 未定义”
@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)
尝试从具有多个 sheet 的 excel 文件制作一些带有散景的图。想要使用 for 循环,这样我就不必为每个 sheet 一遍又一遍地创建数据帧。无法正常工作。以下是代码:
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:名称 'df_sp' 未定义”
@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)