Converting a pandas dataframe to an MNE object

  • MNE version 1.3.1
  • operation system: Windows 10

Hello there,

I hve access to a MEG dataset, which has already been preprocessed with fieldtrip (meaning artifact rejection (…) and epoching) and been converted to a CSV file. I would now like to work with that csv file using mne python.

There are 269 sensors available and I do have information about the underlying sensor layout as its the CTF275 montage. I would now like to visualize my data using something like plot.topo_map() and so on. As far as I am concered, this would require my data to be an evoked object. However, my data is merely a pandas dataframe.

Is there any chance on converting my pandas dataframe into an evoked/mne object, so I can use it for further analysis, including visualisations? I cant seem to find an answer to this.

To be very specific, my data is in long format consisting of the following columns:

Sensor Time Value Item Block Trialorder Cond Participant

It has the data from 38 participants and 269 sensors. Within each participant and each sensor the time start at 1.615 seconds and ends at 2.39, if that is of any help.

I appreciate any help and any further information greatly.

Best

You could reshape the underlying data to 38 3D arrays (one for each participant) of shape (n_epochs, n_channels, n_times), which you can then convert into mne.Epochs objects using mne.EpochsArray(). You can then assign a montage using .set_montage().

1 Like

Hello Clemens,

that was super helpful. Thank you so much!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.