s = {'id': [47035,460,23045,87068,8007,78096],
'st': ['a', 'a', 'd', 'e', 'f', 'a']}
df = pd.DataFrame(s)
# convert to sting and strip away the middle third character then concat
df['id'] = (df['id'].astype(str).str[:2] + df['id'].astype(str).str[3:]).astype(int)
id st
0 4735 a
1 46 a
2 2345 d
3 8768 e
4 807 f
5 7896 a
IIUC公司
使用
str.slice_replace
如下:一种方法是将它们转换为字符串并删除第三个字符,然后再转换回int:
相关问题 更多 >
编程相关推荐