Filter Pandas Data Frame based on exact string match

前端 未结 2 687
花落未央
花落未央 2021-01-05 17:34

I want to filter a pandas data frame based on exact match of a string.

I have a data frame as below

df1 = pd.DataFrame({\'vals\': [1, 2, 3, 4,5], \'i         


        
相关标签:
2条回答
  • 2021-01-05 18:27

    Keeping it simple, this should work:

    df1[df1['ids'] == "aball"] 
    
    0 讨论(0)
  • 2021-01-05 18:33

    You can try this:

    df1[~(df1['ids'] == "aball")] 
    

    Essentially it will find all entries matching "aball" and then negate it.

    0 讨论(0)
提交回复
热议问题