在Pandas中使用Criteria切片数据

时间:2015-12-22 08:55:09

标签: python pandas

我目前正在研究Kaggle's titanic数据集的train.csv。

enter image description here

我是python的新手。我想创建只包含女性的新DataFrame(忽略所有有女性的行)。我正在使用以下命令,但我收到错误:

enter image description here

你们中的任何人都可以看看吗?我遇到过类似的问题,但他们在我的案例中没有帮助......

谢谢,

Ajeet

3 个答案:

答案 0 :(得分:3)

括号错了。尝试

df[df.Sex == 'female']

答案 1 :(得分:1)

你可以通过以下几种方式实现:

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

答案 2 :(得分:0)

试试这个:

<div class="list">
  <div class="panel-title">
    <div class="primary">
      <h2>
        {{ title }}
      </h2>
    </div>  
    <div class="wrapper">
      <div class="secondary">
        <div class="dropdown">
          <a class="button dropdown-toggle on-dark" data-toggle="dropdown">
            <fa name="ellipsis-v"></fa>
            <b class="caret"></b>
          </a>
        </div>
      </div>
    </div>
  </div>
</div>