Python 无法将字符串转换为浮点:';产品_0332';

Python 无法将字符串转换为浮点:';产品_0332';,python,pandas,python-3.7,Python,Pandas,Python 3.7,我可以申请。像 Product_Code Warehouse Product_Category Date Order_Demand 0 Product_0332 Whse_J Category_021 05-01-17 1 1 Product_1909 Whse_J Category_019 29-12-16 1 但未将字符串转换为浮点。如果要提取数值部分,如0332和1909,则只需应用:

我可以申请。像

   Product_Code    Warehouse   Product_Category   Date       Order_Demand

0  Product_0332    Whse_J     Category_021        05-01-17   1
1  Product_1909    Whse_J     Category_019        29-12-16   1

但未将字符串转换为浮点。

如果要提取数值部分,如
0332
1909
,则只需应用:

df = pd.DataFrame(data)

df['Product_Code'] = df['Product_Code'].astype(float)
或者还希望转换为数字格式,如float,结果为
332
1909
,然后在表达式末尾添加
astype('float')

df['Product_Code'] = df['Product_Code'].str.extract('(\d+)')
在第二种情况下,您可以对
df['Product\u code']
应用arthmetic操作

df['Product_Code'] = df['Product_Code'].str.extract('(\d+)').astype('float')