Created
June 5, 2018 13:32
-
-
Save jplsightm/5d4734b3b637c21db226718632a794ce to your computer and use it in GitHub Desktop.
Take a directory of files and apply a function to those files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def process_files(path, extention, func, *args, **kwargs): | |
""" | |
Take a directory of files and apply a function to those files. | |
The first parameter of the function (`func`) must be a file name. This is typically | |
the file to parse to df before apply some function | |
""" | |
dfs = {} | |
for fname in os.listdir(path): | |
# print (os.path.splitext(fname)[-1]) | |
if os.path.splitext(fname)[-1] == extention: | |
rs = func(os.path.join(path, fname), *args, **kwargs) | |
dfs[fname] = rs | |
return dfs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment