I would like to export subjects’ epochs as separate csv files, so that I could import them and run some stats in R. I know that the method to_data_frame() is able to convert epochs into long-format pandas.
I would also need export epoch file to store the metadata associated to the mne.epochs object. As far as I could understand from the wiki, the metadata won’t be stored as part of the dataframe. I guess I can just left-join metadata to the epochsPd by calling pandas.concatenate(), but I was wondering if there was a way to do it within the to_data_frame() method.
Hello, honestly I would just keep metadata and Epochs data in two separate tables, since metadata only makes sense per epoch, whereas Epochs.to_data_frame() produces one row per sample. You would have to endlessly duplicate the metadata if you joined the two tables, which I don’t think is a great idea…
For those interested in the issue, here’s a solution.
Your Epochs object will retain all metadata (as long as you’ve defined the argument metadata when epoching) of all non-bad epochs. So you can extract the metadata and make it a pandas dataframe and then merge it to the epochs dataframe.
epochsPd = epochs.to_data_frame(long_format=True)
goodWords = epochs.metadata.reset_index() #reset the index to be able to refer to it when merging it with the epochs pandas
epochsPd = pd.merge(epochsPd, goodWords, left_on='epoch', right_index=True)
The merge method will match each row index of the goodWords dataframe with the value of each epoch as stored in the epoch column in the epochsPd.
Hi,
Thank you for the entry and the solution! I am also trying to save epochs data with its metadata to run lmm. It was quite helpful, but I couldn’t get what pd is. It would be great if you explain.