I have a data frame and I only want to plot the frequency of one column, for example, the count of cars of different brands. Cars: [FORD, FORD, BMW, GMC, GMC, GMC, GMC.....] I want to plot them in pie charts of any suitable graphs, without using matplotlib.
I tried to create pivot tables, which are like Ford: 4, Chevy: 3, BMW: 5, GMC: 10. but I don't know how to access the column labels and I can't use them in plotly.
You can groupby cars
and get the counts in a new column count
like so
df.groupby(['cars'])['cars'].count().reset_index(name='count')
Then you may use Plotly to render a pie chart like so
import plotly.express as px fig = px.pie(df, values='count', names='cars', title='Cars') fig.show()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.