Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

166
Visualizações
how to set 2 rows to become header in a dataframe with originally has a header?

I am facing problem on how to set another 2 rows be my header.

In a dataframe I have one header, and now I want take my first row and second row become header. Below is my dataframe code:

pvm=pd.DataFrame(pvm)

How can I add header=[0,1] into above code?
Or need start from the table style?

tableyy = final.style.set_table_attributes('border="" clas= "dataframe table table-hover table-bordered"').set_precision(10).render()
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

It seems you need iloc with assign to columns names:

df.columns = [df.iloc[0], df.iloc[1]]

and if need remove this rows:

df = df.iloc[2:].reset_index(drop=True)
df.columns.names = (None, None)

Sample:

df = pd.DataFrame({'A':[1,2,3],
                   'B':[4,5,6],
                   'C':[7,8,9]})

print (df)
   A  B  C
0  1  4  7
1  2  5  8
2  3  6  9

df.columns = [df.iloc[0], df.iloc[1]]
df = df.iloc[2:].reset_index(drop=True)
df.columns.names = (None, None)
print (df)
   1  4  7
   2  5  8
0  3  6  9
over 4 years ago · Santiago Trujillo Relatório

0

I can't fully understand what you want to achieve, but I will try to guess:

pvm.columns = ['0', '1', *df.columns[2:]]

is it what you intend to get?

Example:

import pandas as pd
df = pd.DataFrame({'A':[1,2,3],
                   'B':[4,5,6],
                   'C':[7,8,9]})
print (df)
print('==========')
df.columns = ['0', '1', *df.columns[2:]]
print (df)

gives:

"""
   A  B  C
0  1  4  7
1  2  5  8
2  3  6  9
=========
   0  1  C
0  1  4  7
1  2  5  8
2  3  6  9
"""
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda