Python Forum

Full Version: Comparing two columns with same value but different font format
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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.'
>>>