1

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.

1
  • Please provide enough code so others can better understand or reproduce the problem. Commented Jul 4, 2022 at 16:49

1 Answer 1

3

You can groupby cars and get the counts in a new column count like so

df = 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()

Have some pie!

Sign up to request clarification or add additional context in comments.

1 Comment

I had to save the new DataFrame into a separate variable, which I then used for my pie chart, but then it worked. Great, thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.