0

I try to write to txt file list with russian string.(I get that with unique1 = np.unique(df['search_term']), it's numpy.ndarray)

thefile = open('search_term.txt', 'w')
for item in unique1:
    thefile.write("%s\n" % item)

But in list this string looks correct. But after writing it looks like

 предметов berger bg bg045-14 отзывы
 звезд 
 воронеж

Why a get that?

NineWasps
  • 2,081
  • 8
  • 28
  • 45

1 Answers1

0

Try writing to the file like this:

import codecs

thefile = codecs.open('search_term.txt', 'w', encoding='utf-8')  
for item in unique1:
    thefile.write("%s\n" % item)

The problem is that the file likely is encoded correctly hence why the characters will display incorrectly.

Daniel Waghorn
  • 2,997
  • 2
  • 20
  • 33