How To Create A Pie Chart In Python Using Plotly & Excel | Tutorial [EASY] 💻

Опубликовано: 07 Октябрь 2024
на канале: Coding Is Fun
12,495
132

👉 Explore All My Excel Solutions: https://pythonandvba.com/solutions

𝗗𝗘𝗦𝗖𝗥𝗜𝗣𝗧𝗜𝗢𝗡
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
Did you know you can use Python code to create a pie chart? This is a tutorial that will show you how to create one using Python. For this particular tutorial, we will be using Plotly & Excel.

You can do all the changes in the excel file and after running the script again you will have your updated pie chart.

The Pie Chart is also interactive. If you hover over the chart, you will see the percent share for each category and you can even hide/unhide certain categories dynamically. The final chart will be also saved in a HTML file. Hence, you could also send the chart to your friends & colleagues, who do not even need to have Python installed on their machines.

This tutorial is focusing on beginners in Python. Even you have never written a single line of code in Python, you will be able to have your pie chart by the end of this tutorial.

✅ Chapters:
0:00 Demo
0:45 Tutorial
6:30 Outro

Source code incl. Excel file: https://github.com/Sven-Bo/python-sim...

===================================================
👩‍💻 SOURCE CODE:
import plotly.express as px
import pandas as pd
import plotly

Read data from excel
df = pd.read_excel('data.xlsx')
values = df['Results']
names = df['Category']


fig = px.pie(df,
values=values,
names=names,
title='Survey Results'
)

fig.update_traces(
textposition='inside',
textinfo='percent+label'
)

fig.update_layout(
title_font_size = 42,
)


Export Waterfall to HTML
plotly.offline.plot(fig,filename='Piechart.html')

𝗧𝗢𝗢𝗟𝗦 𝗔𝗡𝗗 𝗥𝗘𝗦𝗢𝗨𝗥𝗖𝗘𝗦
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
🆓【𝗙𝗥𝗘𝗘】Excel Add-in (𝗠𝘆𝗧𝗼𝗼𝗹𝗕𝗲𝗹𝘁): https://pythonandvba.com/mytoolbelt
📊 Dashboard Excel Add-In (𝗚𝗿𝗮𝗳𝗹𝘆): https://pythonandvba.com/grafly
🎨 Cartoon Charts Excel Add-In (𝗖𝘂𝘁𝗲𝗣𝗹𝗼𝘁𝘀): https://pythonandvba.com/cuteplots
🤪 Fun Emoji Excel Add-In (𝗘𝗺𝗼𝗷𝗶𝗳𝘆): https://pythonandvba.com/emojify
📑 Excel Templates: https://pythonandvba.com/go/excel-tem...
🎓 My Courses: https://pythonandvba.com/go/courses
📚 Books, Tools, and More: https://pythonandvba.com/resources

𝗖𝗢𝗡𝗡𝗘𝗖𝗧 𝗪𝗜𝗧𝗛 𝗠𝗘
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
🔗 LinkedIn:   / sven-bosau  
📸 Instagram:   / codingisfun_official  
💻 GitHub: https://github.com/Sven-Bo
💬 Discord: https://pythonandvba.com/discord
📬 Contact: https://pythonandvba.com/contact
☕ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲?
If you want to support this channel, you can buy me a coffee here: https://pythonandvba.com/coffee-donation