2 回答

TA貢獻(xiàn)1878條經(jīng)驗(yàn) 獲得超4個(gè)贊
假設(shè)您確定數(shù)據(jù)始終是您可以嘗試的格式
# Split data and store in separate columns
sample_data['YYYY'] = sample_data[0].str[:4]
sample_data['MM'] = sample_data[0].str[4:]
0 YYYY MM
0 201801 2018 01
1 201702 2017 02
2 201803 2018 03
3 201904 2019 04

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超8個(gè)贊
這也是一個(gè)選擇
sample_data=pd.DataFrame(['201801','201702','201803','201904'])
for i in sample_data:
sample_data = str(i[0:4] + "/" + i[4:6])
print(sample_data)
產(chǎn)量:2018/01,2017/02, 2018/03, 2019/04
添加回答
舉報(bào)