简体   繁体   中英

for scorecardpy.woe_bin package in python I am getting "TypeError: unhashable type: 'numpy.ndarray'"

Python is having scorecardpy library for scorecard development which is alternative to R pacakge scorecardpy

but while running woe_binning from scorecardpy as follow

  bins = sc.woebin(df_temp,y=target_var,positive='bad|1') 

  
  #df_temp is dataframe with all columns having 'float64' data type
  #y is binary variable having data type 'int'

I was getting error for few variables

TypeError: unhashable type: 'numpy.ndarray

others were getting binned properly. i tried finding. difference between variable where binning was successful vs binning was failing basis few parameters as follows

  • Null value
  • dtypes
  • shape

in order to understand the pattern with following code


unhashable_nparray = []
successfully_binned = []


for j,i in enumerate(df3.columns):

    try:
        print(i)
        df_temp = pd.DataFrame()
        df_temp[i] = df3[i]
        df_temp[target_var] = y
        bins = sc.woebin(df_temp,y=target_var,positive='bad|1') 
        successfully_binned.append(i)
        print(i,"---{a}---{b}----{c}--{d}---{z}----Success".format(z =df3[i].nunique()  ,a = df3[i].shape, b=df3[i].isna().sum(),c=type(df3[i]),d=df3[i].dtypes))

    except TypeError:
        unhashable_nparray.append(i)
        print(i,"---{a}---{b}----{c}--{d}---{z}----Fail".format(z =df3[i].nunique(),a = df3[i].shape, b=df3[i].isna().sum(),c=type(df3[i]),d=df3[i].dtypes))

but I could not find any pattern.

what could be the cause of this?

Here is the solution

This error is already reported. and getting discussed here but unfortunately the language is Chinese it is difficult to read.

this error doesn't necessarily mean that your dataframe is uncleaned.or having not expected datatype

please check your pandas version

import pandas as pd
pd.__version__

if output is > 1.4.0 that means you are using recent version of pandas than what scorecardpy is expecting

as of today scorecardpy expects you to work on pandas version <= 1.3.5

so please install pandas == 1.3.5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM