Для следующего фрейма данных :
Код: Выделить всё
import pandas as pd
d=['Hello', 'Helloworld']
f=pd.DataFrame({'strings':d})
f
strings
0 Hello
1 Helloworld
(Включены все возможные трехбуквенные комбинации.)
р>
Код: Выделить всё
[['Hel', 'ell', 'llo'],['Hel', 'ell', 'llo', 'low', 'owo', 'wor', 'orl', 'rld']]
Код: Выделить всё
['wor', 'Hel', 'ell', 'owo', 'llo', 'rld', 'orl', 'low']
Код: Выделить всё
#Shingle into strings of exactly 3
def shingle(word):
r = [word[i:i + 3] for i in range(len(word) - 3 + 1)]
return [''.join(t) for t in r]
#Shingle (i.e. "hello" -> "hel","ell",'llo')
r=[shingle(w) for w in f['strings']]
#Get all elements into one list:
import itertools
colsunq=list(itertools.chain.from_iterable(r))
#Remove duplicates:
colsunq=list(set(colsunq))
colsunq
['wor', 'Hel', 'ell', 'owo', 'llo', 'rld', 'orl', 'low']
Подробнее здесь: https://stackoverflow.com/questions/406 ... das-column
Мобильная версия