Intro
- query in的用法
- 对 dataframe的某个列,执行正则匹配,筛选相应行
query in
import pandas as pd
df = pd.DataFrame({"x": [1, 2, 3], "y": ['ab', 'bc', 'cd']})
df.query("x in [1,2]")
x_in = [2,3]
df.query('x in @x_in')
正则匹配筛选
df
df.y.str.contains("a")
0 True
1 False
2 False
Name: y, dtype: bool
df.query("x>0 and y.str.contains('a')", engine='python')
# 匹配d结尾的字符串
df.query("x>0 and y.str.contains('d$',regex=True)", engine='python')
Ref
[1] https://pandas.pydata.org/pandas-docs/version/0.15/generated/pandas.core.strings.StringMethods.contains.html
2022-04-25 于南京市江宁区九龙湖 大雨
评论列表(0条)