How to select rows that do not start with some str in pandas?

前端 未结 5 1019
别跟我提以往
别跟我提以往 2020-12-29 04:34

I want to select rows that the values do not start with some str. For example, I have a pandas df, and I want to select data do not start with t, a

5条回答
  •  伪装坚强ぢ
    2020-12-29 05:15

    You can use str.startswith and negate it.

        df[~df['col'].str.startswith('t') & 
           ~df['col'].str.startswith('c')]
    
    col
    1   mext1
    3   okl1
    

    Or the better option, with multiple characters in a tuple as per @Ted Petrou:

    df[~df['col'].str.startswith(('t','c'))]
    
        col
    1   mext1
    3   okl1
    

提交回复
热议问题