Stack data from a list in pandas

Asked

Viewed 46 times

-1

I’m trying to stack several csv files that are listed in a csv file type, but when I apply iteration on them I just preview the last file.

Follows the code.

 import pandas as pd
 import numpy as np

 lista = pd.read_csv('lista.csv') - (neste arquivo contém a lista com o nome dos arquivos dentro da pasta em csv)


 lista = lista['.ipynb_checkpoints'].values.tolist()

 for i in lista:
     i = pd.read_csv(i,sep=';')

print(i)

I wanted to save a variable with each file in the list, then stack them all.

Thanks for the help,

Hugs,

1 answer

0

Tried to use list comprehension? It seems to me that your code is not very suitable to perform the desired terefa. Try to change this yours for by the following

l = [pd.read_csv(i,sep=';') for i in lista]

in the end, l will contain a list of all the dataFrames you want, once you have made sure that the variable lista contains the strings with the proper filenames.

I hope I helped, hug!

Browser other questions tagged

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