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

Viewed 37

Given dataset has no of columns and the question is to find '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'])

I have just started with python and came up with code to find the GDP of UK, but not sure how to compare it with other values of GDP column

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

If you are looking for equality, you could do:

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