Reputation: 26027
I have a dataframe I'm working on and trying to find a specific value that is impacting my analysis. Apparently there is a cell with a value "<" in it and I'm struggling to find the specific cell.
I tried this:
print(df[df.isin(['<'])].stack())
which I believe should show the value, except I believe this is searching for an exact match whereas I'm looking for a partial match.
How can I do a wild card search on the entire data frame?
Upvotes: 1
Views: 1852
Reputation: 75100
For partial matches, use instead of isin
, series.str.contains
with na=false
for handling NaN
values(also check the other paremeters) and also if using stack
, do the stack first and then find the indexes with boolean indexing
which will give you the rows and column labels where the condition matches:
s = df.stack().str.contains('<',na=False)
output_indices = s[s].index
Upvotes: 4