英文:
using loc with upper()
问题
我试图获取所有值,在大写情况下等于"EU"的值。下面是我的解决方案,但不起作用。有谁知道我应该如何做到这一点?
companies_df.loc[(companies_df["location"].str.upper() == 'EU')].head(10)
英文:
I'm trying to bring back all values that, in upper case, equal "EU". My solution below doesn't work. Does anybody know how I would do this?
companies_df.loc[(upper(companies_df["location"]) == 'EU')].head(10)
答案1
得分: 2
问题出在你的代码中,upper
函数没有正确应用于 location
列。在 pandas 中,你可以使用 str
访问器来对列应用字符串方法。
companies_df.loc[companies_df["location"].str.upper() == 'EU'].head(10)
英文:
The issue with your code is that the upper
function is not applied correctly to the location
column. In pandas, you can use the str
accessor to apply string methods to a column.
companies_df.loc[companies_df["location"].str.upper() == 'EU'].head(10)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论