【发布时间】:2021-11-06 03:49:13
【问题描述】:
我正在尝试从整数格式的列中获取月份
'''dvd['yy'] = str(dvd['CalendarYearMonth'])[:3]
dvd['mon'] = str(dvd['CalendarYearMonth'])[4:6]'''
但得到以下输出
CalendarYearMonth CountryCode Dividends yy mon
0 202108 CN 196.0 0 2
1 202109 CN 380.0 0 2
2 202108 IN NaN 0 2
3 202109 IN 115.0 0 2
谁能帮我获得正确的输出 - dvd 是输入 DF
【问题讨论】:
-
因为你想要 int 或 sting 作为输出?对于 int,请检查 my answer
标签: python pandas string datetime