我有一个系列df2,我想用饼图
绘制kubectl patch configmap nginx-config -p '{"LogFormat":\'$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_time <"$request_body" >"$resp_body"\'}'
我试过了
Index
Friday 2
Thursday 2
Wednesday 3
ValueError:无法将字符串转换为float:'Wednesday'
答案 0 :(得分:2)
考虑pd.Series
-
s
Index
Monday 2
Tuesday 4
Wednesday 5
Thursday 2
Friday 1
Saturday 6
Sunday 3
Name: counts, dtype: int64
现在,在pd.Series.plot.pie
列上调用counts
-
s.plot.pie(y=df.index,
shadow=False,
colors=colors,
explode=(0, 0, 0, 0, 0.15, 0, 0), # exploding 'Friday'
startangle=90,
autopct='%1.1f%%')
plt.axis('equal')
plt.tight_layout()
plt.show()
别打电话给plot()
!在pie
上致电plot
。
如果您需要按工作日排序索引,请务必将其转换为pd.Categorical
-
cat = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday', 'Sunday']
df.index = pd.Categorical(df.index, categories=cat, ordered=True)
df = df.sort_index()
然后,您可以如上图所示进行绘图。
答案 1 :(得分:0)