【发布时间】: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