从列中的字符串中删除不需要的部分 [英] Remove unwanted parts from strings in a column

查看:78
本文介绍了从列中的字符串中删除不需要的部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种有效的方法来从DataFrame列的字符串中删除不需要的部分.

I am looking for an efficient way to remove unwanted parts from strings in a DataFrame column.

数据如下:

    time    result
1    09:00   +52A
2    10:00   +62B
3    11:00   +44a
4    12:00   +30b
5    13:00   -110a

我需要将这些数据修剪为:

I need to trim these data to:

    time    result
1    09:00   52
2    10:00   62
3    11:00   44
4    12:00   30
5    13:00   110

我尝试了.str.lstrip('+-')和.str.rstrip('aAbBcC'),但是出现了错误:

I tried .str.lstrip('+-') and .str.rstrip('aAbBcC'), but got an error:

TypeError: wrapper() takes exactly 1 argument (2 given)

任何指针将不胜感激!

推荐答案

data['result'] = data['result'].map(lambda x: x.lstrip('+-').rstrip('aAbBcC'))

这篇关于从列中的字符串中删除不需要的部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆