python - Seaborn Countplot 中的布尔掩码
问题描述
我想应用这个布尔掩码
csv["country"].value_counts()>5000
到这个函数
sns.countplot(y = csv["country"].value_counts()>5000, data = csv)
但它会引发这个错误:
"Unalignable boolean Series provided as indexer (index of the boolean Series and of the indexed object do not match)".
我应该如何进行?
解决方案
您可以执行以下操作:
s = csv['country'].value_counts()
s[s > 5000].plot(kind='bar')
要使用 seaborn,您可以使用以下方法过滤数据:
s = csv['country'].value_counts()
s = s[s > 5000].index.tolist()
sns.countplot(x='country', data=csv.query("country in @s")) # option1
# sns.countplot(x='country', data=csv.loc[df["country"].isin(s))) # option2
推荐阅读
- python - 如何在 python 中处理不平衡数据?
- linux - 程序如何依赖 Linux 中的共享库?
- visual-studio - 如何使用 vtk 编写一系列 DICOM 图像
- java - 如何在新的导航抽屉架构组件中实现分享应用或评分应用或注销功能
- javascript - 在highcharts中查找日期和时间之间的差异
- user-interface - 画布上的 Unity 粒子效果
- php - 选择值所在的数组
- ios - 如何使用 UICollectionViewController 设置具有多个部分的 1 标头
- javascript - 如何在进行另一个函数调用时停止执行 javascript/jquery
- python-3.x - 在python中设置请求刷新率