Type error: unhashable type 'list' while selecting subset from specific columns pandas dataframe

28,175

You need to write your column names in one list not as list of lists:

df3_query = df3[['Cont NUMBER', 'PL NUMBER', 'NAME', 'LOAN COUNT', 'SCORE    MINIMUM', 'COUNT PERCENT']]

From docs:

You can pass a list of columns to [] to select columns in that order. If a column is not contained in the DataFrame, an exception will be raised. Multiple columns can also be set in this manner

Share:
28,175
User1090
Author by

User1090

Updated on January 30, 2020

Comments

  • User1090
    User1090 over 4 years

    I have a dataframe that has about 20 columns and I am trying to get a subset of the dataframe by selecting only some specific columns about 6. My line of code is:

    df3_query = df3[['Cont NUMBER'],['PL NUMBER'],['NAME'],['LOAN COUNT'],['SCORE    MINIMUM'],['COUNT PERCENT']]
    

    I am getting an error as

    TypeError: unhashable type: 'list'
    

    May I know the reason in which why I get this error? Also I would like to select only those columns from the df3 dataframe. Can anyone help me on this?