过滤掉包含特定单词的列

时间:2016-03-11 12:56:58

标签: python pandas dataframe

在pandas DataFrame中,我需要过滤掉那些包含单词' fixed'的列。然后我想创建另一个只包含那些列的DataFrame。我怎么能这样做?

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;    

@Entity
    public class User {

        public User() {
        }

        public User(String username, String password) {
            super();
            this.enabled=false;
        }

        @Id
        @GeneratedValue
        private Long id;

        @NotNull
        @Size(min=1, max=45)
        private String username;

        @NotNull
        @Size(min=1, max=60)
        private String password;

        @NotNull
        @Column(name = "enabled")
        private boolean enabled;

        @NotNull
        @Size(min=1, max=45)
        private String email;

        private Integer condo_id;

        @NotNull
        private List<String> roles;
    }

1 个答案:

答案 0 :(得分:2)

只需使用.ix属性:

fixed = [c for c in dataset.columns if c.startswith("fixed")]
fixed_dataset = dataset.ix[:, fixed]

同样的情况:

non_fixed = [c for c in dataset.columns if not c.startswith("fixed")]
dataset.ix[:, non_fixed]