我正在编写代码来执行以下操作:
我已经成功地设计了1-3,但不能让4按需要工作;该图表不是使用相同的类别值(“questionresponse”变量)对列表进行分组,而是将系列添加到新的未命名列中,如下所示:
如何根据系列的“问题-回答”值强制将其添加到条形图中的类别中
以下代码注释:问题_数据是从Excel工作表中提取的数据框。它的确切字段和数据与这个问题无关
chart_data = CategoryChartData()
chart_data.categories = testweek_list
categoryvalues = []
for questionresponse in questionresponse_list:
for test_week in testweek_list:
categoryvalue = question_data.loc[(question_data['Test Week'] == test_week) & (question_data['Response Option'] == questionresponse), 'Count'].values.astype(int)
if (categoryvalue != 0) and (categoryvalue != ""):
categoryvalues.append(int(categoryvalue))
chart_data.add_series(questionresponse, categoryvalues)
x, y, cx, cy = Inches(2), Inches(2), Inches(6), Inches(4.5)
questionslide.shapes.add_chart(XL_CHART_TYPE.COLUMN_STACKED_100, x, y, cx, cy, chart_data)
i+=1
下面是期望结果的示例(忽略图中的值,仅用于说明目的):
目前没有回答
相关问题 更多 >
编程相关推荐