Skip to content

Instantly share code, notes, and snippets.

@Swarchal
Created July 14, 2016 15:00
Show Gist options
  • Select an option

  • Save Swarchal/3e598355330a74f82b226aaea4d20808 to your computer and use it in GitHub Desktop.

Select an option

Save Swarchal/3e598355330a74f82b226aaea4d20808 to your computer and use it in GitHub Desktop.
import os
import pandas as pd
# get the file paths
my_path = "path/to/output"
# stolen from stack overflow
def get_filepaths(directory):
"""Get full filepaths of all files in a directory, including sub-directories"""
file_paths = []
for root, directories, files in os.walk(directory):
for filename in files:
# Join the two strings in order to form the full filepath.
filepath = os.path.join(root, filename)
file_paths.append(filepath)
return file_paths
# Run the above function and store its results in a variable.
file_paths = get_filepaths(my_path)
# now want to merge all the data tables together
# N.B this is assuming we have multi-indexed column names (i.e CellProfiler merged object output)
pd.read_concat((pd.read_csv(f, header=[0,1]) for f in file_paths))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment