[英]sklearn SimpelImputer SystemError: <built-in function _abc_instancecheck> returned a result with an error set
I'm imputing missing values in a pipeline.我在管道中输入缺失值。
In a first step I bin the variable in using:在第一步中,我将使用的变量装箱:
df_listings['original.listing.rooms.bedrooms.count'] = pd.cut(df_listings['original.listing.rooms.bedrooms.count'], bins = [1,2,3,4,5,6,10,50])
df_listings = df_listings.fillna(np.nan)
In a second step I want to impute the column using在第二步中,我想使用
si = SimpleImputer(missing_values=np.nan,strategy="most_frequent")
si.fit_transform(df_listings[['original.listing.rooms.bedrooms.count']])
Even though I followed this flow with other variables, here I get the following error:尽管我使用其他变量遵循此流程,但在这里我收到以下错误:
TypeError: unsupported operand type(s) for +: 'pandas._libs.interval.Interval' and 'pandas._libs.interval.Interval'
The above exception was the direct cause of the following exception:
...
SystemError: <built-in function _abc_instancecheck> returned a result with an error set
I can't understand the reason why I get this error.我无法理解我收到此错误的原因。 For other variables, I can work with pandas.Interval, just this variable causes an issue.对于其他变量,我可以使用 pandas.Interval,只是这个变量会导致问题。
当我们处理分类数据时,将 .astype(str) 添加到您的 pd.cut 可以解决问题。
df_listings['original.listing.rooms.bedrooms.count'] = pd.cut(df_listings['original.listing.rooms.bedrooms.count'], bins = [1,2,3,4,5,6,10,50]).astype(str)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.