0

I'm writing from pandas to csv like this:

df.to_csv(extractpath+'/extract_{}'.format(locname))

Now, when locname variable contains croatian characters, I get error

*UnicodeEncodeError: 'ascii' codec can't encode character '\u0161' in position 53: ordinal not in range(128)*

The only workaround I come up with is this:

df.to_csv(extractpath+'/extract_{}'.format(locname.encode('utf-8')))

However, although error is now gone, file names are not correct anymore, for example they look like:

*extract_b'Vara\xc5\xbedin'* instead of *extract_Varaždin*

How can I properly solve the problem?

ParthS007
  • 2,581
  • 1
  • 22
  • 37
Ivan Toman
  • 123
  • 1
  • 9
  • I hope this helps https://stackoverflow.com/a/9942822/7994074 – ParthS007 Jun 17 '19 at 07:21
  • @ParthS007 Unfortunatelly didn't help. I've gone through that question several times and still not sure what I did wrong. The most voted answer tells the OP to do pretty much what I did in my shown attempt. Can you suggest more in detail what to try? – Ivan Toman Jun 17 '19 at 07:56

1 Answers1

0

I had wrongly set LANG variable in shell, without realizing it., so when I executed python script from shell script it didn't work. Now is fine after correcting LANG variable.

Ivan Toman
  • 123
  • 1
  • 9