Код: Выделить всё
import pandas as pd
import random
from string import ascii_letters
from timeit import default_timer as timer
# Create dataframe
df = pd.DataFrame(data=list(range(100000000)), columns=["id"])
df['searchtext'] = [''.join(random.choice(ascii_letters) for x in range(3)) for _ in range(len(df))]
df['hash'] = df.searchtext.transform(hash)
print(df)
# Standard text search
start = timer()
df[df.searchtext == 'aaa']
end = timer()
print(f'text search took {end-start} seconds')
# Search using hash
start = timer()
df[df.hash == hash('aaa')]
end = timer()
print(f'text search took {end-start} seconds')
Подробнее здесь: https://stackoverflow.com/questions/784 ... n-a-string