原表 data
订单编号 物流费用
0 19160394 0.2513
1  19140861 0.1513
2  19160333 0.1513
需要变成这样的形式
订单编号 物流费用
0 19160394 0.2513
1 19140861 0.1513
2 19160333 0.1513
我用了这样的方法
data['订单编号'].str.extract('([0-9]+)')
这样我方法就不能提出第0列(19160394)这个,因为这个是int类型
各位有办法?
用pandas 写
import pandas as pd
frame = pd.DataFrame([
[19160394, 0.2513],
[' 19140861', 0.1513],
[' 19160333', 0.1513],
],index=[1,2,3], columns=['订单编号', '物流费用'])
def isnum(x):
if isinstance(x, int ) or isinstance(x, float):
return x
elif isinstance(x, str):
return int("".join(list(filter(str.isdigit, x))))
frame['订单编号'] = frame['订单编号'].apply(isnum)
frame