AttributeError Traceback (most recent call last)
<ipython-input-104-f3f6e3d4a02d> in <cell line: 9>()
7
8 # apagamos o $ e as vírgulas com apply lambda
----> 9 dt_data['preco'] = dt_data['preco'].apply(lambda x: x.replace('$', '').replace(',',''))
10
11 # transformamos os tipos de dados para float64
5 frames
lib.pyx in pandas._libs.lib.map_infer()
<ipython-input-104-f3f6e3d4a02d> in <lambda>(x)
7
8 # apagamos o $ e as vírgulas com apply lambda
----> 9 dt_data['preco'] = dt_data['preco'].apply(lambda x: x.replace('$', '').replace(',',''))
10
11 # transformamos os tipos de dados para float64
AttributeError: 'float' object has no attribute 'replace'
Então usei assim:
import numpy as np
dt_data['preco'].fillna('0.0', inplace = True)
dt_data['preco'] = dt_data['preco'].apply(lambda x: str(x).replace('$', '').replace(',',''))
dt_data['preco'] = dt_data['preco'].astype(np.float64)
dt_data