xxxxxxxxxx
### For comparing two strings
from thefuzz import fuzz
# Compare reeding vs reading
fuzz.WRatio('Reeding', 'Reading') # 86
### For comparing a string with a series
from thefuzz import process
from fuzzywuzzy import process # Alternative
# Define string and array of possible matches
string = "Houston Rockets vs Los Angeles Lakers"
choices = pd.Series(['Rockets vs Lakers', 'Lakers vs Rockets',
'Houson vs Los Angeles', 'Heat vs Bulls'])
# Return highest 2 matches in format (string_in_series, similarity_score, index)
process.extract(string, choices, limit = 2)
#### See more : Python record linkage documentation
## https://recordlinkage.readthedocs.io/en/latest/guides/link_two_dataframes.html
xxxxxxxxxx
# Comparison is done through "lexicographic" order of letters
# Change the variable 'word' then run and see the results
# Remember a capital letter comes before a simple letter
word = 'banana'
if word == 'banana':
print('All right, bananas.')
if word < 'banana':
print('Your word', word, 'comes before banana')
elif word > 'banana':
print('Your word', word, 'comes after banana')
else:
print('All right, bananas.')
xxxxxxxxxx
==: This checks whether two strings are equal
!=: This checks if two strings are not equal
<: This checks if the string on its left is smaller than that on its right
<=: This checks if the string on its left is smaller than or equal to that on its right
>: This checks if the string on its left is greater than that on its right
>=: This checks if the string on its left is greater than or equal to that on its right
xxxxxxxxxx
string1 = "hello"
string2 = "Hello"
if string1 == string2:
print("The strings are equal.")
else:
print("The strings are not equal.")