将 Excel 工作簿从内存写入文件时出错没有系列?

问题描述

我正在尝试创建一个包含多个工作表的 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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...