Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
417 views
in Technique[技术] by (71.8m points)

python - invalid value encountered in true_divide and unhashable type: 'list' Errors while appending to a list

As a part of my explanatory data analysis I would like to run a script which checks all columns in my data frame to find the out the variables in which the proportion of number of unique values to the count of values is less than 25%. This behaviour will enable me to find categorical variables even their data type is numeric.

treshold_for_category = 0.25
mostly_cat = {}
category_column_list = list()
for var in df.columns:
   mostly_cat[var] = 1.*df[var].nunique()/df[var].count() < 
                        treshold_for_category
for key, value in mostly_cat.items():
    if value:
       category_column_list.append(key)

After running the code I'm getting the following error:

invalid value encountered in true_divide

unhashable type: 'list'

Could you please support me to fix the issue?

question from:https://stackoverflow.com/questions/65929459/invalid-value-encountered-in-true-divide-and-unhashable-type-list-errors-whil

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...