Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[ ] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
df['DIA_DA_SEMANA'] = df.DAT_EMISSAO.dt.day_name()
df['DIA'] = df.DAT_EMISSAO.dt.day
df['MÊS'] = df.DAT_EMISSAO.dt.month_name(locale='Portuguese') # OUTPUT: Error: unsupported locale setting
df['ANO'] = df.DAT_EMISSAO.dt.year
df
Traceback
Error Traceback (most recent call last)
Cell In[24], line 3
1 df['DIA_DA_SEMANA'] = df.DAT_EMISSAO.dt.day_name()
2 df['DIA'] = df.DAT_EMISSAO.dt.day
----> 3 df['MÊS'] = df.DAT_EMISSAO.dt.month_name(locale='Portuguese')
4 df['ANO'] = df.DAT_EMISSAO.dt.year
5 df
File ~/.local/lib/python3.10/site-packages/pandas/core/accessor.py:94, in PandasDelegate._add_delegate_accessors.<locals>._create_delegator_method.<locals>.f(self, *args, **kwargs)
93 def f(self, *args, **kwargs):
---> 94 return self._delegate_method(name, *args, **kwargs)
File ~/.local/lib/python3.10/site-packages/pandas/core/indexes/accessors.py:126, in Properties._delegate_method(self, name, *args, **kwargs)
123 values = self._get_values()
125 method = getattr(values, name)
--> 126 result = method(*args, **kwargs)
128 if not is_list_like(result):
129 return result
File ~/.local/lib/python3.10/site-packages/pandas/core/indexes/extension.py:98, in _inherit_from_data.<locals>.method(self, *args, **kwargs)
96 if "inplace" in kwargs:
97 raise ValueError(f"cannot use inplace with {type(self).__name__}")
---> 98 result = attr(self._data, *args, **kwargs)
99 if wrap:
100 if isinstance(result, type(self._data)):
File ~/.local/lib/python3.10/site-packages/pandas/core/arrays/datetimes.py:1212, in DatetimeArray.month_name(self, locale)
1175 """
1176 Return the month names with specified locale.
1177
(...)
1208 Index(['January', 'February', 'March'], dtype='object')
1209 """
1210 values = self._local_timestamps()
-> 1212 result = fields.get_date_name_field(
1213 values, "month_name", locale=locale, reso=self._reso
1214 )
1215 result = self._maybe_mask_results(result, fill_value=None)
1216 return result
File ~/.local/lib/python3.10/site-packages/pandas/_libs/tslibs/fields.pyx:179, in pandas._libs.tslibs.fields.get_date_name_field()
File ~/.local/lib/python3.10/site-packages/pandas/_libs/tslibs/fields.pyx:622, in pandas._libs.tslibs.fields._get_locale_names()
...
618 # convert to string
619 locale = normalize(_build_localename(locale))
--> 620 return _setlocale(category, locale)
Error: unsupported locale setting
Issue Description
I'm trying to set a month column for my DF with portuguese names by doing as the docs said, but it didn't work, I even tried with 'English'
which says it is the default but it doesn't work either.
Expected Behavior
I expect it to return a serialized column with month names in Portuguese
Installed Versions
Comment From: MarcoGorelli
hi @eduardochaves1
what's the output of locale -a
for you?
Comment From: eduardochaves1
hi @eduardochaves1
what's the output of
locale -a
for you?
Ow, I didn't know about this command, and I just found out by this command's output that the right way to set the locale attribute was with locale="pt_BR.utf8"
(for Brazilian Portuguese). Thank you for helping me with that!
Maybe a good tip was to modify the dt.day_name
and dt.month_name
pandas documentations with that command in mind so the users can know how to set their language in the right way?
Comment From: MarcoGorelli
yup - do you want to make a PR?
Comment From: eduardochaves1
I'd like to, actually it would be my first time helping an open source project :sweat_smile:. But the closest thing i found on the repo was this path. Wich is not what I expected from the original doc page I read.
Comment From: MarcoGorelli
here's the docstring
https://github.com/pandas-dev/pandas/blob/bcb6c1adf5f18465389dad781436626dddd6c64b/pandas/core/arrays/datetimes.py#L1198-L1209