问题
I have following dataframe
import pandas as pd
data=['5Star','FiveStar','five star','fiv estar']
data = pd.DataFrame(data,columns=["columnName"])
When I try to filter with one condition it works fine.
data[data['columnName'].str.contains("5")]
Output:
columnName
0 5Star
But It gives an error when doing with multiple conditions.
How to filter it for conditions five and 5?
Expected Output:
columnName
0 5Star
2 five star
回答1:
Use str.contains
with a string with values separated by '|'
:
print(data[data['columnName'].str.contains("5|five")])
Output:
columnName
0 5Star
2 five star
来源:https://stackoverflow.com/questions/53812967/how-to-filter-string-in-multiple-conditions-python-pandas