'How to load 2nd modified file in folder
I have to create a automated script in which I have to make sure that the 2nd modified/updated file needs to be picked as a data frame in Python.
Eg: Suppose I have a folder Test and in that I have 2 file 2022-03-24.csv and 2022-03-23.csv so when I run my Python script system should automatically run 2022-03-23.csv file since it's updated or created on 23rd March.
Below is the code which I am using but this code is used to load most recent data i.e. 2022-03-24.csv file
import glob
import os.path
import pandas as pd
folder_path = r'C:\Users\Ron\Desktop\Test'
file_type = r'\*csv'
files = glob.glob(folder_path + file_type)
max_file = max(files, key=os.path.getctime)
import_file = pd.read_csv(max_file)
print(import_file)
I want to load 2nd modified data i.e. 2022-03-23.csv
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
