badar
1
dear boss
see my simple code for pie chart by df but it give me error
import streamlit as st
import pandas as pd
df = pd.DataFrame({
'Name': ['Aparna'] * 5 + ['Juhi'] * 5 + ['Suprabhat'] * 5,
'votes_of_each_class': [12, 9, 17, 19, 20, 11, 15, 12, 9, 4, 22, 19, 17, 19, 18]
})
st.pyplot(df.groupby('Name').sum().plot( kind='pie', y='votes_of_each_class', autopct='%1.0f%%'))
this is error
please give me the right code
edsaac
2
Initialize the matplotlib figure first and then tell pandas to draw the plot there:
import pandas as pd
import matplotlib.pyplot as plt
import streamlit as st
df = pd.DataFrame(
{
"Name": ["Aparna"] * 5 + ["Juhi"] * 5 + ["Suprabhat"] * 5,
"votes_of_each_class": [12, 9, 17, 19, 20, 11, 15, 12, 9, 4, 22, 19, 17, 19, 18],
}
)
fig, ax = plt.subplots()
df.groupby("Name").sum().plot(kind="pie", y="votes_of_each_class", autopct="%1.0f%%", ax=ax)
st.pyplot(fig)