By loading my xlsx file into pandas, the rows have become column indexes. How to set a new input for columns?

Asked

Viewed 79 times

0

I would like to know how to set new index for columns.

data = pd.read_excel('numero_automoveis_vendidos.xlsx')
data.columns
Index([7, 5, 9, 11, 10, 8, '9.1', 6, '8.1', '10.1'], dtype='object')

inserir a descrição da imagem aqui

  • 1

    Use header=None in the call for pd.read_excel, thus: data = pd.read_excel('numero_automoveis_vendidos.xlsx', header=None)

  • You can add in the question an example of how the data is saved in file . xlsx? and how should the expected output be?

  • I ran with header = None and it worked very well, thank you very much.

1 answer

0

#Importa a Biblioteca Pandas
import pandas as pd

print('=== original ===')
df = pd.read_excel('ABC.xlsx');
print(df)
print()

print('=== Modo 1 ===')
#Seta None no index e header(ou numero de inicio de leitura da linha)
df = pd.read_excel('ABC.xlsx', index_col=None, header=None);
print(df)
print()

print('=== Modo 2 ===')
#Seta None header(ou numero de inicio de leitura da linha)
df = pd.read_excel('ABC.xlsx', header=None, names=['Produto','Valor','Unidade']);
print(df)
print()

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.