[Python] Making several pieplots from dataframe columns

Discussão em 'Python' iniciado por Stack, Junho 9, 2025.

  1. Stack

    Stack Membro Participativo

    I made a dataframe from some data that looks like the following

    df = pd.Dataframe({'Keys': ['key1','key2','key3']
    'Percentage':[63,37,89]}


    I want to create 3 piecharts that show the percentage for each key. Thought it was going to be easy but all I could find was how to create a chart that contains all 3 keys.

    The quick way to fix it would be to create some lists for every key and make the chart based on that but is it there a way to do this more efficiently?

    Edit:

    I'd like to create something like this for each key

    import matplotlib.pyplot as plt

    fig1, ax1 = plt.subplots()
    labels = ['key1_yes','key1_no']
    sizes = [63,37]

    ax1.set_title('key1')

    ax1.pie(sizes, labels=labels, autopct='%1.1f%%',
    shadow=True, startangle=90)

    Continue reading...

Compartilhe esta Página