(20210129已解决)Pandas通过某列值包含特定字符串过滤行

  • Overview

    Maybe expressed with english by:

    how to filter rows containing a string pattern from a Pandas dataframe?

  • 问题解析

    只保留某些行,其中某列包含特定的字符串。

  • 解决方案

    df[df['col_name'].str.contains('str_pattern')]
    

    如果包含多种str_pattern:

    df[df['col_name'].str.contains('sp1') | df['col_name'].str.contains('sp2')]
    
  • References

  1. How to filter rows containing a string pattern from a Pandas dataframe [duplicate]

你可能感兴趣的:(#,小白学Python,Pandas,filter,特定字符串)