ENH: Return locale based month_name and weekday_name values (#12805, #12806) by mroeschke · Pull Request #18164 · pandas-dev/pandas (original) (raw)
@mroeschke We could turn weekday_name and month_name into functions that can accept a locale argument and default it to 'en_US.UTF8'? I think that would be clean, but it would definitely be an API change.
@jreback hmm, that's an idea. we could could make new ones weekday_names() (and then just deprecate weekday_name
That's an option. Another option is to leave it as is but to clearly document in those attributes how to get your locale dependent names. Eg it would be nice that the following would work:
In [26]: import calendar
In [27]: dt = pd.date_range('2016-01-01', periods=10, freq='10D')
In [28]: dt.weekday
Out[28]: Int64Index([4, 0, 3, 6, 2, 5, 1, 4, 0, 3], dtype='int64')
In [29]: dt.weekday.map(calendar.day_name)
...
TypeError: '_localized_day' object is not callable
(the problem here is that calendar.day_name
is some kind of mapping (it has __getitem__
) but not really)
This works:
In [32]: pd.Series(dt.weekday).map({i: calendar.day_name[i] for i in range(7)})
Out[32]:
0 Friday
1 Monday
2 Thursday
3 Sunday
4 Wednesday
5 Saturday
6 Tuesday
7 Friday
8 Monday
9 Thursday
dtype: object
(second issue is that Index.map
apparently does not work with dict, while Series.map
does)
But I think both issues could be solved to make this easier.