问题描述
我正在尝试创建一个包含多个工作表的 Excel 工作簿。我不断收到错误 Chart1 必须至少包含一个数据系列。参见chart.add_series()我已经在网上阅读pandas excel文档有一段时间了,我已经阅读了stackoverflow中的帖子,但我似乎无法解决这个问题。
df = pd.DataFrame(
{
"Video": cr_dst_list,"Timestamp": cr_ts_list,"CP": cr_cp_list,"Raw Filesize": cr_raw_fsize_list,"Encoded Filesize" : cr_enc_fsize_list,"CR": cr_compression_ratio_list,"MSSSIM": vq_msssim_list
}
)
last_row = max_profile + 1
# Create Excel workbook
excel_file = f'{dst_path}profile_analysis.xlsx'
writer = pd.ExcelWriter(excel_file)
# Create a Pandas Excel writer using XlsxWriter as the engine
for vid in cr_dst_list:
df_vid = df.loc[df['Video'] == vid]
#df_vid = df_vid.drop(columns=[0])
df_vid = df_vid.drop(columns=[ 'Video','Timestamp','Raw Filesize','Encoded Filesize' ])
# Convert the dataframe to an XlsxWriter Excel object
df_vid.to_excel(writer,sheet_name=vid)
# Get the xlsxwriter workbook and worksheet objects
workbook = writer.book
worksheet = writer.sheets[vid]
# Create a chart object
chart = workbook.add_chart( {'type': 'scatter'} )
# Configure the series of the chart from the dataframe data
series = f'=vid!$C$2:$C${last_row+1}'
chart.add_series({
'values': '=\'vid\'series','data_labels': {
'value': True,'position': 'above'
},})
# Add a chart title and some axis labels.
chart.set_title ({
'name': vid,'name_font': {
'name': 'Calibri','color': 'blue',},})
chart.set_x_axis({
'name': 'Compression Profile','name_font': {
'name': 'Courier New','color': '#92D050'
},}),chart.set_y_axis({
'name': 'Compression Ratio','name_font': {
'name': 'Century','color': 'red'
},'num_font': {
'bold': True,'italic': True,'underline': True,'color': '#7030A0',})
# Set an Excel chart style.
chart.set_style(6)
# Insert the chart into the worksheet (with an offset)
worksheet.insert_chart('F2',chart)
writer.save()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)