Answers for "pandas reading each xlsx file in folder"

0

read all excel using glob

import sys
import csv
import glob
import pandas as pd

# get data file names
path =r'C:\DRO\DCL_rawdata_files\excelfiles'
filenames = glob.glob(path + "/*.xlsx")

dfs = []

for df in dfs: 
    xl_file = pd.ExcelFile(filenames)
    df=xl_file.parse('Sheet1')
    dfs.concat(df, ignore_index=True)
Posted by: Guest on July-05-2020
0

pandas reading each xlsx file in folder

import os
import pandas as pd
import openpyxl as excel
import glob



#setting up path

path = 'data_inputs'
extension = 'xlsx'
os.chdir(path)
files = [i for i in glob.glob('*.{}'.format(extension))]

#Grouping files - brings multiple files of same type together in a list 

wild_groups = ([s for s in files if "wild" in s])
domestic_groups = ([s for s in files if "domestic" in s])

#Sets up a dictionary associated with the file groupings to be called in another module 
file_names = {"WILD":wild_groups, "DOMESTIC":domestic_groups}
...
Posted by: Guest on October-02-2020
0

pandas reading each xlsx file in folder

import pandas as pd
import glob

# your path to folder containing excel files
datapath = "\\Users\\path\\to\\your\\file\\"

# set all .xls files in your folder to list
allfiles = glob.glob(datapath + "*.xls")

# for loop to aquire all excel files in folder
for excelfiles in allfiles:
    raw_excel = pd.read_excel(excelfiles)

# place dataframe into list
list1 = [raw_excel]
Posted by: Guest on October-02-2020

Python Answers by Framework

Browse Popular Code Answers by Language