[英]Slicing Data Using Criteria in Pandas
括号是错误的。 尝试
df[df.Sex == 'female']
您可以通过几种方式来做到这一点:
df = df[df['columnname'] =='whatever'] # keeps only rows that have that value in that column
df = df[df['columnname'] !='whatever'] # the opposite of before. keeps only those that do not have that value
df = df[df['columnname'].isin('whatever','whatever')] # if you want to use multiple values
df = df[~df['columnname'].isin('whatever','whatever')] # the opposite of before
df = df[df['columnname'] > 5] # works also like this
尝试这个:
df[(df['Sex']=='female')]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.