Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

pie chart drawing for a specific column in pandas python

I have a dataframe df, which has many columns. In df["house_electricity"], there are values like 1,0 or blank/NA. I want to plot the column in terms of a pie chart, where percentage of only 1 and 0 will be shown. Similarly I want to plot another pie chart where percentage of 1,0 and blank/N.A all will be there.

customer_id house_electricity house_refrigerator
cid01 0 0
cid02 1 na
cid03 1
cid04 1
cid05 na 0
#I wrote the following but it didnt give my my expected result
import pandas as pd
import matplotlib.pyplot as plt

df=pd.read_csv("my_file.csv")

df_col=df.columns



df["house_electricity"].plot(kind="pie")
#I wrote the following but it didnt give my my expected result
import pandas as pd
import matplotlib.pyplot as plt

df=pd.read_csv("my_file.csv")

df_col=df.columns



df["house_electricity"].plot(kind="pie")

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

For a dataframe

df = pd.DataFrame({'a':[1,0,np.nan,1,1,1,'',0,0,np.nan]})
df

a
0   1
1   0
2   NaN
3   1
4   1
5   1
6   
7   0
8   0
9   NaN

The code below will give

df["a"].value_counts(dropna=False).plot(kind="pie")

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading