Python Forum
Merging spreadsheets with the same columns and extracting rows with matching entries
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Merging spreadsheets with the same columns and extracting rows with matching entries
#4
import os
import pandas as pd 
cwd = os.path.abspath('K:\\ExternalLinkValidationReports\\UK\\2020-01-06')
files = os.listdir(cwd)
df = pd.DataFrame()
for file in files:
     if file.endswith('.xlsx'):
         df = df.append(pd.read_excel(file), ignore_index=True) 
df.head()
df.to_excel('Appended Reports.xlsx')
So far I've managed to create an appended report that collects and appends all the Excel files in K:\\ExternalLinkValidationReports\\UK\\2020-01-06

However, I want to modify this so that it looks for the latest modified folder in K:\\ExternalLinkValidationReports\\UK\\
rather than having to specify the exact folder each time.

I wonder if anyone knows a quick way to modify my code so that it can do this?

Many thanks!

John
Reply


Messages In This Thread
RE: Merging spreadsheets with the same columns and extracting rows with matching entries - by johnbernard - Aug-19-2021, 03:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Combining Spreadsheets Py3_14 4 605 Feb-07-2024, 04:58 PM
Last Post: deanhystad
  Converting a json file to a dataframe with rows and columns eyavuz21 13 4,432 Jan-29-2023, 03:59 PM
Last Post: eyavuz21
  merging rows arvin 2 827 Dec-24-2022, 04:56 AM
Last Post: arvin
  Extracting Data into Columns using pdfplumber arvin 17 5,550 Dec-17-2022, 11:59 AM
Last Post: arvin
  How to properly format rows and columns in excel data from parsed .txt blocks jh67 7 1,877 Dec-12-2022, 08:22 PM
Last Post: jh67
  Check DataFrames with different sorting in columns and rows Foxyskippy 0 778 Nov-19-2022, 07:49 AM
Last Post: Foxyskippy
  The code I have written removes the desired number of rows, but wrong rows Jdesi1983 0 1,631 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983
  making variables in my columns and rows in python kronhamilton 2 1,619 Oct-31-2021, 10:38 AM
Last Post: snippsat
  rows from sql query need to write to a file as columns sjcsvatt 6 2,389 Oct-09-2021, 12:45 AM
Last Post: snippsat
  Summing up rows and columns plumberpy 3 2,267 Aug-18-2021, 05:46 AM
Last Post: naughtyCat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020