如何将向量拆分为 2 列并更改为 float 类型?

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

我试图将这个 (34218.1, 37413.8] 拆分为 2 列,最小值和最大值,但是当我这样做时,这两列代表对象,但我想成为 float 类型。所以这是我的代码:

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

所以,我分成了2列,但是我不能转换成float类型。请帮助我

你不是在设置系列,你只是返回一个视图。尝试:

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