问题描述
我有以下数据。
df3[~df3['total_sqft'].apply(is_float)].head(10)
在上述数据中,我在 total_sqft 列中具有 3067-8156 之类的值,并且我试图在最小值和最大值的平均值中找到范围,但使用下面的代码,但这会抛出一个错误。
def convert_sqft_to_num(x):
tokens = x.split('-')
if len(tokens) == 2:
return (float(tokens[0])+float(tokens[1]))/2
try:
return float(x)
except:
return None
df4 = df3.copy()
df4.total_sqft = df4.total_sqft.apply(convert_sqft_to_num)
df4 = df4[df4.total_sqft.notnull()]
df4.head(2)
错误消息
AttributeError: 'int' object has no attribute 'split'
请帮助我更正代码。
此致
巴拉斯·维卡斯
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)