Я пробовал это -
Код: Выделить всё
import pptx
from pptx import Presentation
from pptx.chart.data import CategoryChartData
from pptx.enum.chart import XL_CHART_TYPE
from pptx.util import Inches
import pandas as pd
excelfile1 = pd.read_excel("1st.xlsx",sheet_name="sheet1")
excelfile2 = pd.read_excel("2nd.xlsx",sheet_name="sheet1")
df1 = excelfile1.iloc[177:183,20:23]
df2 = excelfile2.iloc[177:183,21:23]
df1.columns = ["Range","PDF (%)","CDF (%)"]
df2.columns = ["PDF (%)","CDF (%)"]
df = pd.concat([df1,df2],axis=1)
print(df)
# create presentation with 1 slide ------
prs = Presentation("Template.pptx")
slide = prs.slides[10]
# define chart data ---------------------
chart_data = CategoryChartData()
chart_data.categories = df1["Range"]
chart_data.add_series('PDF %', df1["PDF (%)"])
# add chart to slide --------------------
x, y, cx, cy = Inches(1), Inches(1), Inches(6), Inches(4.5)
cchart = slide.shapes.add_chart(
XL_CHART_TYPE.COLUMN_CLUSTERED, x, y, cx, cy, chart_data
)
# chart_data1 = CategoryChartData()
# chart_data1.categories = df1["Range"]
chart_data.add_series('CDF %', df1["CDF (%)"])
# add chart to slide --------------------
x, y, cx, cy = Inches(1), Inches(1), Inches(6), Inches(4.5)
slide.shapes.add_chart(
XL_CHART_TYPE.LINE, x, y, cx, cy, chart_data
)
prs.save('chart-01.pptx')
Вывод из кода
Не могли бы вы мне помочь? где я ошибаюсь?
Подробнее здесь: https://stackoverflow.com/questions/782 ... excel-data