0

I'm trying to change the language of a column week_names from English to Spanish

This is the code :

dias_semana=pd.to_datetime(fechas['Fecha'], format='%Y/%m/%d').dt.day_name(locale= "Spanish")
dias_semana=pd.DataFrame(dias_semana)

and the error is this:

Error: unsupported locale setting

I'm running python in Jupyter notebook, Mac OS Big Sur 11.1.

Shaido
  • 27,497
  • 23
  • 70
  • 73
  • Does this answer your question? [Error: "unsupported locale setting" on Python / OSX](https://stackoverflow.com/questions/17994358/error-unsupported-locale-setting-on-python-osx) – Axiumin_ Jan 19 '21 at 23:33

1 Answers1

0

I think you can try to import the locale library first:

import locale

locale.setlocale(category=locale.LC_ALL,
                 locale="German"  # Note: do not use "de_DE" as it doesn't work)

In your case, you would replace German by Spanish

You also might have some luck with:

try:
    import locale
    locale.setlocale(locale.LC_ALL, 'en_US.utf8')
except Exception:
    try:
        locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
    except Exception as e:
        messages.error(request, 'An error occurred: {0}'.format(e))

It is also possible to set LC_ALL in your environment by running the following command:

$ export LC_ALL=C

If that doesn't help, then you can try to install dpkg using sudo port install dpkg or brew (http://macappstore.org/dpkg/)

And then the following:

export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
sudo dpkg-reconfigure locales

For your case, I believe the locale would be 'es_ES.UTF-8'

QuirkyBit
  • 654
  • 7
  • 20