【问题标题】:pie chart drawing for a specific column in pandas pythonpandas python中特定列的饼图绘制
【发布时间】:2023-02-08 13:55:27
【问题描述】:

我有一个数据框 df,它有很多列。在 df["house_electricity"] 中,有像 1,0 或 blank/NA 这样的值。我想根据饼图绘制该列,其中将仅显示 1 和 0 的百分比。同样,我想绘制另一个饼图,其中 1,0 的百分比和空白/N.A 都将在那里。

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")

【问题讨论】:

    标签: python pandas dataframe matplotlib


    【解决方案1】:

    尝试

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-01
      • 2023-04-06
      • 2014-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多