使用 Pandas 如何找到满足条件的值的计数?

Using Pandas how to find the count of values that satisfies a condtn?

给定的数据集没有列,问题是找到 'How many countries have a GDP greater than the GDP of UK?'

df=pd.DataFrame(columns=['S.No','Country','Population','Land_area','Median_Age','GDP','GDP_per_capita'])

我刚开始使用 python 并想出了查找英国 GDP 的代码,但不确定如何将它与 GDP 列的其他值进行比较

df2[df2.Country=='United Kingdom']["GDP"]

如果你正在寻找平等,你可以这样做:

uk_gdp = df2[df2.Country=='United Kingdom']["GDP"]
df2[df2["GDP"] == uk_gdp]