Python Forum
Comparing two columns with same value but different font format - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Comparing two columns with same value but different font format (/thread-39140.html)



Comparing two columns with same value but different font format - doug2019 - Jan-08-2023

Hi! I have a column of a dataframe with city names in capital letters and I wanted to compare it with the cities column of another dataframe with regular letters. It would be like a join. Join the two columns to compare the values ​​and search if any of them are missing. Below an example of the columns and values:

df1([CITY])
df1
CITY
WASHINGTON D.C.
NEW YORK
SAN DIEGO

df2([City])
df2
City
Washington D.C.
New York
San Diego


RE: Comparing two columns with same value but different font format - Larz60+ - Jan-08-2023

just cast both strings to lower (or upper) then compare:

example:
>>> city1 = 'WASHINGTON D.C.'
>>> city2 = 'Washington D.C.'
>>> 
>>> # without changing case:
>>> city1 == city2
False
>>> 
>>> # with case change:
>>> city1.lower() == city2.lower()
True
>>> 
>>> # original variable names remain as they were:
>>> city1
'WASHINGTON D.C.'
>>> city2
'Washington D.C.'
>>>