更新时间:2023-11-22 08:46:52
Matplotlib的pyplot是熊猫在其plot函数中使用的库.熊猫的情节只是方便的捷径. 对于条形图的问题:我建议使用Seaborn的 barplot ,类别为色调. 如果您只想使用熊猫,那么也许是这样的:
Matplotlib's pyplot is the library that Pandas use in their plot function. Pandas' plot is only a convenient shortcut. For the bar chart question: I would suggest using Seaborn's barplot, using the desired category as hue. If you wish to only use Pandas, then maybe something like:
df = pd.DataFrame(np.random.rand(10, 1), columns=['col_name'])
df['category'] = df.col_name>0.5
print(df)
col_name category
0 0.053908 False
1 0.136295 False
2 0.325790 False
3 0.362942 False
4 0.919924 True
5 0.406884 False
6 0.433959 False
7 0.725699 True
8 0.582537 True
9 0.608040 True
df.groupby('category').count().plot(kind='bar', legend=False)