add to_df method in BIDSLayout
@@ -257,20 +257,29 @@ class BIDSLayout(object):
for deriv in self.derivatives.values():
self.entities.update(deriv.entities)
- # def to_df(self, **kwargs):
- # """
- # Return information for all Files tracked in the Layout as a pandas
- # DataFrame.
-
- # Args:
- # kwargs: Optional keyword arguments passed on to get(). This allows
- # one to easily select only a subset of files for export.
- # Returns:
- # A pandas DataFrame, where each row is a file, and each column is
- # a tracked entity. NaNs are injected whenever a file has no
- # value for a given attribute.
- # """
- # return self.as_data_frame(**kwargs)
+ def to_df(self, **kwargs):
+ """
+ Return information for all Files tracked in the Layout as a pandas
+ DataFrame.
+
+ Args:
+ kwargs: Optional keyword arguments passed on to get(). This allows
+ one to easily select only a subset of files for export.
+ Returns:
+ A pandas DataFrame, where each row is a file, and each column is
+ a tracked entity. NaNs are injected whenever a file has no
+ value for a given attribute.
+ """
+ try:
+ import pandas as pd
+ except ImportError:
+ raise ImportError("What are you doing trying to export a BIDSLayout"
+ " as a pandas DataFrame when you don't have "
+ "pandas installed? Eh? Eh?")
+ files = self.get(return_type='obj', **kwargs)
+ data = pd.DataFrame.from_records([f.entities for f in files])
+ data.insert(0, 'path', [f.path for f in files])
+ return data
def __repr__(self):
n_sessions = len([session for isub in self.get_subjects()
