glob

How to have an ordered list of files with digits?

How to have an ordered list of files with digits? Question: I have a folder of files and want to read the files one by one because it is frames of a video. However, when I am trying to have an ordered list of files, it is ordered as follows: data_dir = ‘./data/’ filenames =listdir(data_dir) …

Total answers: 2

Concatenating CSVs into dataframe with filename column

Concatenating CSVs into dataframe with filename column Question: I am trying to concat multiple CSVs that live in subfolders of my parent directory into a data frame, while also adding a new filename column. /ParentDirectory │ │ ├───SubFolder 1 │ test1.csv │ ├───SubFolder 2 │ test2.csv │ ├───SubFolder 3 │ test3.csv │ test4.csv │ ├───SubFolder …

Total answers: 2

how to read specific JSON files using python glob

how to read specific JSON files using python glob Question: i have a set of JSON files in a folder. Sample files: -2022_06_13_07_14_f71cd512135bdab9.json -2022_06_13_07_1421_f71cd512135bdab9.json -2022_06_13_07_12314_f71cd512135bdab9.json -2022_06_14_132_14_f71cd512135bdab9.json -2022_06_14_74647_14_f71cd512135bdab9.json Instead of reading all files at once, I need to read them day-wise. ex:2022_06_13_07_14_f71cd512135bdab9.json corresponding to 2022_06_13. like wise I need to read all the JSON files and …

Total answers: 1

Scanning subdirectories for files that match certain filenames

Scanning subdirectories for files that match certain filenames Question: I want to scan a directory and all its subdirectories for certain file names (i.e. all files having an .log extension, as well as all files whose names are example1.txt or example2.txt), so I can process them further. I succeded in fetching all files ending with …

Total answers: 1

Concatenate a .xls file list into .csv

Concatenate a .xls file list into .csv Question: I’m trying to concatenate a .xls file list into .csv: import glob import pandas as pd file_xls = glob.glob(location + "*.xls") print(file_xls) read_file = pd.read_excel(location + file_xls) but I have an error about the concatenation of the list: TypeError: can only concatenate str (not "list") to str …

Total answers: 2

Collecting Sheet Names from a Folder of Excel Workbooks

Collecting Sheet Names from a Folder of Excel Workbooks Question: I have a folder of numerous .xslx files on my desktop and I am trying to iterate through them one by one to collect the respective sheet names automatically from each workbook. import openpyxl import glob # specifying the path to csv files path = …

Total answers: 2

Open multiple files with the same extension in a folder

Open multiple files with the same extension in a folder Question: I want to open all files with the same extension (.dat) in the same directory. This is my current code: path = Path(".") # current directory extension = ".dat" file_with_extension = next(path.glob(f"*{extension}")) if file_with_extension: with open(file_with_extension, encoding=’utf-8′) as infile, open(‘462888.dat’, ‘w’, encoding=’utf-8′) as outfile: …

Total answers: 1

Iterate through all sheets of all workbooks in a directory

Iterate through all sheets of all workbooks in a directory Question: I am trying to combine all spreadsheets from all workbooks in a directory into a single df. I’ve tried with glob and with os.scandir but either way I keep only getting the first sheet of all workbooks. First attempt: import pandas as pd import …

Total answers: 1