Check orthography in pandas data frame column using Enchant library

135 Views Asked by At

I'm new to pandas and enchant. I want to check orthography in short sentences using python.

I have a pandas data frame:

id_num      word
1           live haapy
2           know more
3           ssweam good
4           eeat little
5           dream alot

And I want to achieve the next table with column “check”

id_num         word           check
1              live haapy     True, False
2              know more      True, True
3              ssweam good    False, True
4              eeat little    False, True
5              dream alot     True, False

What is the best way to do this?

I tried this code:

import enchant
dic = enchant.Dict("ru_Eng")
df['list_word'] = df['word'].str.split() #Get list of all words in each sentence using split()
row = list()
for row in df[['id_num', 'list_word']].iterrows():
r = row[1]
for word in r.list_word:
    rows.append((r.id_num, word))
df2 = pd.DataFrame(rows, columns=['id_num', 'word']) #Make the table with id_num column and a column of separate words

Then I got new data frame (df2):

id_num    word
1         live
1         haapy
2         know
2         more
3         ssweam
3         good
4         eeat
4         little
5         dream
5         alot

After that I check words using:

column = df2['word'] for i in column: n = dic.check(i) print(n)

The result is:

True
False
True
True
False
True
False
True
True
False

Check is carried out correctly but when I tried to put this result to a new pandas data frame column I got all False values for all words.

for i in column:
df2['res'] = dic.check(i)

Resulted data frame:

id_num    word    res
1         live   False
1         haapy  False
2         know   False
2         more   False
3         ssweam False
3         good   False
4         eeat   False
4         little False
5         dream  False
5         alot   False

I will be grateful for any help!

0

There are 0 best solutions below