Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

307
Vistas
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

over 4 years ago · Santiago Trujillo
5 Respuestas
Responde la pregunta

0

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)
over 4 years ago · Santiago Trujillo Denunciar

0

I encountered the same error with missing row index labels rather than columns.
For example, I would have a dataset of products with the following ids: ['a','b','c','d']. I store those products in a dataframe with indices ['a','b','c','d']:

df=pd.DataFrame(['product a','product b','product c', 'product d'],index=['a','b','c','d'])

Now let's assume I have an updated product index: row_indices=['b','c','d','e'] in which 'e' corresponds to a new product: 'product e'. Note that 'e' was not present in my original index ['a','b','c','d'].

If I try to pass this updated index to my df dataframe: df.loc[row_indices,:],

I'll get this nasty error message:

KeyError: "Passing list-likes to .loc or [] with any missing labels is no longer supported. The following labels were missing: Index(['e'], dtype='object').

To avoid this error I need to do intersection of my updated index with the original index:

df.loc[df.index.intersection(row_indices),:]  

this is in line with recommendation of what pandas docs

over 4 years ago · Santiago Trujillo Denunciar

0

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).

over 4 years ago · Santiago Trujillo Denunciar

0

I had the same issue while trying to create new columns along with existing ones :

df = pd.DataFrame([[1,2,3]], columns=["a","b","c"])
def foobar(a,b):
  return a,b
df[["c","d"]] = df.apply(lambda row: foobar(row["a"], row["b"]), axis=1)

The solution was to add result_type="expand" as an argument of apply() :

df[["c","d"]] = df.apply(lambda row: foobar(row["a"], row["b"]), axis=1, result_type="expand")
over 4 years ago · Santiago Trujillo Denunciar

0

This error pops up if indexing on something which is not present - reset_index() worked for me as I was indexing on a subset of the actual dataframe with actual indices, in this case the column may not be present in the dataframe.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda