清理数据帧python中的数据。我需要将价格从str转换为十进制,分别为str的零

清理数据帧python中的数据。我需要将价格从str转换为十进制,分别为str的零,python,python-3.x,dataframe,machine-learning,data-cleaning,Python,Python 3.x,Dataframe,Machine Learning,Data Cleaning,我想通过用相应的零替换'Cr'和'lac'将价格列转换为int(请参阅) 首先,您需要设置一个进行转换的函数。然后使用apply()在所有价格上运行它。只要确保您有某种错误检查,以防价格以意外的形式出现 def price_fl(price_str): conv = {'Cr':10000000, 'Lac':100000} s = price_str.split() return float(s[0]) * conv.get(s[1])

我想通过用相应的零替换'Cr'和'lac'将价格列转换为int(请参阅)


首先,您需要设置一个进行转换的函数。然后使用apply()在所有价格上运行它。只要确保您有某种错误检查,以防价格以意外的形式出现

def price_fl(price_str):    
        conv = {'Cr':10000000, 'Lac':100000}
        s = price_str.split()
        return float(s[0]) * conv.get(s[1])

df['prices'] = df['prices'].apply(price_fl)

您的图像不可见。粘贴持久链接。