1.以xxx开头

  1. # 方法1:endswith函数
  2. df[df.num.str.endswith('o')]
  3. # 方法2:contains函数+正则表达式
  4. df[df.num.str.contains('o$')]
  5. # 方法3:query函数
  6. df.query("num.str.endswith('o')",engine='python')

2.以XXX结尾

  1. # 方法1:endswith函数
  2. df[df.num.str.endswith('o')]
  3. # 方法2:contains函数+正则表达式
  4. df[df.num.str.contains('o$')]
  5. # 方法3:query函数
  6. df.query("num.str.endswith('o')",engine='python')

3.包含XXX的

  1. # 方法1:contains函数+正则表达式
  2. df[df.num.str.contains('o')]
  3. # 方法2:query函数
  4. df.query("num.str.contains('o')",engine='python')