newleaf
newleaf

Reputation: 2457

pandas dataframe match string in any place( column name or any cell)

So far found there is a way to match string in particular column using df['A'].str.contains(re.compile("[Dd]ate")). This is a way to find column A contains "date" or "Date".

How about any place in this dataframe, including column names or any cell? Return True if any column names or cell contains this pattern, else False .

Upvotes: 0

Views: 181

Answers (1)

Stef
Stef

Reputation: 30619

You could convert the whole df (including row and column indices) to a string and then search that string:

re.search('[Dd]ate', df.to_string()) != None

Upvotes: 1

Related Questions