I modified some code that i found online which uses pandas and xlsxwriter to read an excel sheet and generate a chart. Right now it inserts the generated chart into the excel sheet, i want to know if it is possible to insert the chart into a powerpoint presentation.
my dataset:
![[Image: F4KNEBp.png]](https://i.imgur.com/F4KNEBp.png)
code snippet:
my dataset:
![[Image: F4KNEBp.png]](https://i.imgur.com/F4KNEBp.png)
code snippet:
import pandas as pd
excel_file = 'scoresonly.xlsx'
movies = pd.read_excel(excel_file)
df1 = movies['Title']
df2 = movies['IMDB Score']
writer = pd.ExcelWriter( excel_file, engine='xlsxwriter')
# Convert the dataframe to an XlsxWriter Excel object.
df1.to_excel(writer, sheet_name='Sheet1', index=False)
df2.to_excel(writer, sheet_name='Sheet1', startcol=1, index=False)
# Get the xlsxwriter workbook and worksheet objects.
workbook = writer.book
worksheet = writer.sheets['Sheet1']
# Create a chart object.
chart = workbook.add_chart({'type': 'column'})
# Configure the series of the chart from the dataframe data.
chart.add_series({
'categories': ['Sheet1', 1, 0, len(df1), 0],
'values': ['Sheet1', 1, 1, len(df2), 1]})
# Insert the chart into the worksheet.
worksheet.insert_chart('D2', chart)
# Close the Pandas Excel writer and output the Excel file.
writer.save()final result:
