我有:
pd.DataFrame({'price':['45p','£1.35']})
我想将这些转换为数字,并得到:
pd.DataFrame({'price':['45p','£1.35'],'numeric':[0.45,1.35]})
我试过了:
df['numeric']=np.where(df.price.str.contains('p') is True,
pd.to_numeric(df.price.str.replace('p',''))/100,
pd.to_numeric(df.price.str.replace('£','')))
并得到以下错误:ValueError: Unable to parse string "£1.35" at position 7
有什么建议我做错了吗?