To perform case-insensitive string matching in Pandas, you can use the .str
accessor along with regular expressions and the case=False
parameter
(1) parameter case of str.contains
(2) Margin only on columns
(3) Margin only on columns
1. Check if a string contains a word (case-insensitive)
Output:
name
0 maximum
1 Maxxy
2 MAXa
5 MaX
2. Exact match ignoring case
For exact matches (not substrings), normalize strings using .str.lower()
or .str.upper()
:
Result:
name
5 MaX
3. Case-insensitive query
We can perform case-insensitive search with Pandas query like:
Result:
name
5 MaX
Notes:
case=False
works only with.str.contains()
and.str.match()
using regex.- For non-regex comparisons, normalize both sides with
.str.lower()
or.str.upper()
.
Summary
To make your string filters case-insensitive in Pandas:
- Use
.str.contains(..., case=False)
for substring matching. - Use
.str.lower()
or.str.upper()
for exact value comparisons.