How to split vector into 2 columns and change to float type?

Viewed 37

I'm trying to split this (34218.1, 37413.8] into 2 columns, min and max, but when I did it these two columns represent object but I want to be float type. So here you are my code:

df['binnedInc'] = df['binnedInc'].str.strip('[]')#I want to remove righ bracket in case it's a problem
df['binnedInc'] = df['binnedInc'].str.strip('()')#I want to remove left bracket
df[["MinInc","MaxInc"]]=df.binnedInc.str.split(expand=True,pat=",")
df['MaxInc'].astype(float)

MinInc       object #I got this when i want to see df.type    
MaxInc       object

So, I split into 2 columns, but then I can't transform into float type. Please help me

1 Answers

You're not setting the series, you only returning a view. Try:

df['MaxInc'] = df['MaxInc'].astype(float)
Related