我有一组数据,例如:
0 1
0 type 1 type 2
1 type 3 type 4
我怎样才能将它转移到:
0 1
0 1 2
1 3 4
更喜欢使用apply
或transform
函数
最佳答案
>>> df.apply(lambda x: x.str.replace('type ','').astype(int))
0 1
0 1 2
1 3 4
如果不需要转换为 int,请删除 .astype(int)
关于python - Pandas 保留数字部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39221900/