-1

So i have an instance where even after converting my sets to lists, they aren't recognized as lists.

So the idea is to delete extra columns from a data frame comparing with columns in another. I have two data frames say df_test and df_train . I need to remove columns in df_test which are not in train .

 extracols = set(df_test.columns) - set(df_train.columns) #Gives cols 2b 
                                                            deltd
 l = [extracols]       # or  list(extracols)                                                         
 Xdp.dropna( subset = l, how ='any'  , axis = 0)

I get an error : Unhashable type set Even on printing l it prints like a set with {} curlies.

Kris
  • 21
  • 5
  • 1
    Can you please provide more code to give the snippet you've provided better context. Also, can you please make clearer what it is you are asking. Regards! – MorrisLaw May 05 '17 at 16:27

1 Answers1

1

[{set}] doesn't cast to list, it just creates a list of length 1 with your set inside it.

Are you sure that list({set}) isn't working for you? Maybe you should post more of your code as it is hard to see where this is going wrong for you.

  • cols_test = df_test.columns cols_train = df_train.columns extracols = set(cols_test) - set(cols_train) l = list(extracols) Xdp.dropna( subset = l , how ='any' , axis = 0) – Kris May 05 '17 at 17:19