Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

python - Discarding the initial reports in multiple excel and create one dataframe pandas

In a folder,there is multiple excel files with initial unwanted report and the unwanted footer also. Unwanted number of header rows are varying in fie to file. I want to create one dataframe by accessing with folder. Here i attached sample examples.enter image description here

enter image description here

This is what i develop so far and want specific method to clean all excel files.

cd = os.path.dirname(os.path.abspath("D:project"))

i = 0
dfList = []

for root, dirs, files in os.walk(cd):
for fname in files:

   
    if re.match("^.*.xlsx$", fname):
        data = pd.read_excel(os.path.join(root, fname)) # want method to clean and read all files at once not file by file
       
        dfList.append(data)    
        i += 1

df = pd.concat(dfList)

Thanks in advance for your help.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...