Issue
Hey everyone i got an error in my code, while convert string to char.
This how i remove the unit in the data
and then while converting with for i in ['Power']: data[i] = data[i].astype(float)
i got the error message.
Any help, i am very thankfull.
Solution
import pandas as pd
data = {'Power': ['58.6 bhp', '126.2 bhp', '88.7 bhp']}
df = pd.DataFrame(data)
df=df.replace({'Power':'[a-z]'},'',regex=True)
you can use lambda for row wise operation and convert to "float" as below :
df['Power']=df['Power'].apply(lambda row: float(row))
Answered By - vbhatt
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.