【发布时间】:2020-11-09 10:06:34
【问题描述】:
我有一个包含月份列的 df。月份是它们的数值,即从 1 到 12。我需要将它们读取为它们的实际文本等价物,以便将 1 替换为一月,将 2 替换为二月,依此类推。
目前我正在通过分别声明每个月来做这件事:
cntryPerMonth.loc[cntryPerMonth['Month'] == 1.0, 'Month'] = 'January'
cntryPerMonth.loc[cntryPerMonth['Month'] == 2.0, 'Month'] = 'February'
cntryPerMonth.loc[cntryPerMonth['Month'] == 3.0, 'Month'] = 'March'
cntryPerMonth.loc[cntryPerMonth['Month'] == 4.0, 'Month'] = 'April'
cntryPerMonth.loc[cntryPerMonth['Month'] == 5.0, 'Month'] = 'May'
and so on for the remaining months
有没有更有效的方法?
谢谢。
【问题讨论】: