How to transform excel file into list? Python

Asked

Viewed 273 times

0

I wonder how I can turn the excel file into list after reading it

df = pd.read_excel('Data.xlsx')

inserir a descrição da imagem aqui

1 answer

0


Take a look at this link... Your code will look like the one below:

import xlrd
workbook = xlrd.open_workbook('teste.xls') #Use o nome do seu arquivo
worksheet = workbook.sheet_by_name('Planilha1') #Use o nome da aba do seu arquivo
worksheet = workbook.sheet_by_index(0)

lista = []  # Cria a lista vazia
for i in range(worksheet.nrows): 
    valor = worksheet.cell_value(i, 0) # Pega os valores do excel
    lista.append(valor) # Insere os valores na lista

print(lista)
  • You can use the xlrd library to read the file.
  • Create an empty list
  • Use append to include items in your list

Remember that with this code Voce will catch even the value of the first line. Modify your code to what Voce needs.

Browser other questions tagged

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