Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing list-likes to .loc or [] with any missing labels is no longer supported

I want to create a modified dataframe with the specified columns. I tried the following but throws the error "Passing list-likes to .loc or [] with any missing labels is no longer supported"

# columns to keep filtered_columns = ['text', 'agreeCount', 'disagreeCount', 'id', 'user.firstName', 'user.lastName', 'user.gender', 'user.id'] tips_filtered = tips_df.loc[:, filtered_columns]  # display tips tips_filtered 

Thank you

like image 780
swasthik nayak Avatar asked Apr 18 '20 15:04

swasthik nayak


2 Answers

It looks like Pandas has deprecated this method of indexing. According to their docs:

This behavior is deprecated and will show a warning message pointing to this section. The recommended alternative is to use .reindex()

Using the new recommended method, you can filter your columns using:

tips_filtered = tips_df.reindex(columns = filtered_columns).

NB: To reindex rows, you would use reindex(index = ...) (More information here).

like image 131
Joel Oduro-Afriyie Avatar answered Sep 17 '22 20:09

Joel Oduro-Afriyie


Some of the columns in the list are not included in the dataframe , if you do want do that , let us try reindex

tips_filtered = tips_df.reindex(columns=filtered_columns) 
like image 38
BENY Avatar answered Sep 18 '22 20:09

BENY