python - pandas dataframe to powerpoint chart backend
you will need to read a bit about python-pptx.
You need chart's index and slide index of the chart. Once you know them
get your chart object like this->
chart = presentation.slides[slide_index].shapes[shape_index].chart
replacing data
chart.replace_data(new_chart_data)
reset_chart_data_labels(chart)
then when you save your presentation it will have updated the data.
usually, I uniquely name all my slides and charts in a template and then I have a function that will get me the chart's index and slide's index. (basically, I iterate through all slides, all shapes, and find a match for my named chart).
Here is a screenshot where I name a chart->[![screenshot][1]][1]. Naming slides is a bit more tricky and I will not delve into that but all you need is slide_index just count the slides 0 based and then you have the slide's index.
[1]: https://i.stack.imgur.com/aFQwb.png
I have a pandas dataframe result which stores a result obtained from a sql query. I want to paste this result onto the chart backend of a specified chart in the selected presentation. Any idea how to do this?
P.S. The presentation is loaded using the module python-pptx