1.- I have an address that contains 11 files, what I want to do in the function is to read each of the 11 files in the folder and create a different data frame for each of the files:
2.- This is the code I have
def leer_ins(path):
filenames = glob.glob(path + "/*.xlsx")
for i,filename in enumerate(filenames):
nombre = "0" + str(i) + filename
nombre = pd.read_excel(filename, sheet_name = 0)
#list_data.append(data)
return nombre
leer_ins("/Users/ricardo.javier.mart1/Documents/Sabadell/Insumos/Insumos_FinRep")
I can think of a possible solution by defining a List of DataFrames . This would be one
lista
where each element is aDataFrame
. Following your approach, the code would be as follows:The function receives the folder location and returns the list via a list comprehension .
If you want to access for example the first
DataFrame
generated, in this case you should writeprint(resultado[0])
. When doingtype(resultado[0])
the output is :pandas.core.frame.DataFrame
. and when doingtype(resultado)
the output is :list
.