python - Pandas 保留数字部分

标签 python string pandas replace numeric

我有一组数据,例如:

        0       1 
0  type 1  type 2
1  type 3  type 4

我怎样才能将它转移到:

   0  1
0  1  2
1  3  4

更喜欢使用applytransform函数

最佳答案

>>> 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/

相关文章:

c++ - 在 C++ 中从字符串 vector 中删除一个字符

python - 根据时间序列中的先前值和后续值将值替换为 NaN

python - 如何在 `evaluate` 之后使用 `fit` 和 `validation_split` 参数?

python:子进程在使用 sudo 时给我不同的结果

C : Clearing/Overwritting specific space in Array

python - 将句子的字符串表示形式列表转换为词汇集

python - 使用 BeautifulSoup 从多个 XML 列表中提取文本数据

Python 请求 - 为什么在没有 POST 数据的情况下 POST 不退回到 GET?

python - 如何调整行或列中的具体数据?

python - .copy() 不会创建深拷贝