1

My Python toolbox uses a function (code below) to save values to a CSV file. When I was using the same code in a Jupyter notebook, saved records were properly encoded (I am dealing with Polish letters like ć,ą,ę), but when I run my code in ArcGIS Pro as a toolbox script I got results such as BiaĹ‚ostocka instead of Białostocka saved in the CSV.

I tried adding:

# -*- coding: utf-8 -*-

But without any positive results.

Code for function below:

def zapis_do_csv(
        lista_1, lista_2, nazwa_1, 
        nazwa_2, csv_name, katalog, 
        czesc_nazwy):

raw_data = {nazwa_1: lista_1,
            nazwa_2: lista_2}
df = pd.DataFrame(raw_data, columns=[nazwa_1, nazwa_2])
df.to_csv('{0}\{1}_{2}.csv'.format(katalog, czesc_nazwy, csv_name), index=False, header=True)
  • Just a note: what you tried adding is just a comment and has no actual commands. Maybe you could try searching for how to set the default encoding programmatcally. – Jon Nov 15 '18 at 15:16
  • 1
  • Great, glad to help. You should write what worked as a short answer and accept it :) – Jon Nov 16 '18 at 15:08
0

encoding = 'CP1250' did the trick

Below my fixed code:

df.to_csv('{0}\{1}_{2}.csv'.format(katalog, czesc_nazwy, csv_name), index=False, header=True, encoding = 'CP1250')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.