Python Seaborn Countplot中的布尔掩码

Python Seaborn Countplot中的布尔掩码,python,pandas,seaborn,Python,Pandas,Seaborn,我想应用这个布尔掩码 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 mat

我想应用这个布尔掩码

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

这是可行的,但我想使用
sns.countplot
函数。如果我键入
sns.countplot(y=s[s>1000],data=csv)
我不太想得到我想要的!一旦我们将
s
转换为list,是否有办法将
数据设置为s而不必使用
csv.query
?这类似于
sns.countplot(y='country',data=s)
您需要过滤数据,您可以尝试使用
.loc
来过滤数据的选项2。我们也可以用这种方式重写选项2
sns.countplot(y='country',data=csv[csv[“country”].isin(s)])
因为我们不需要
.loc
来访问列