Skip to content

Instantly share code, notes, and snippets.

@jplsightm
Created June 5, 2018 13:32
Show Gist options
  • Save jplsightm/5d4734b3b637c21db226718632a794ce to your computer and use it in GitHub Desktop.
Save jplsightm/5d4734b3b637c21db226718632a794ce to your computer and use it in GitHub Desktop.
Take a directory of files and apply a function to those files.
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