Exporting computed csd_fourier data to Pandas DataFrames

If you have a question or issue with MNE-Python, please include the following info:

  • MNE-Python version: 0.23.0
  • operating system: Windows 10

Hello,

I have created an epoch that contains several events and then computed the CSD in 120 frequencies using the csd_fourier method, and now I would like to convert all the generated data from each frequency in each EEG channel in each event in the epoch to Pandas data frame. :sweat_smile:
Because I want to use the data as an input to the classifier.

Any advice on what is the easiest way to do it?

Thanks in advance

If you plan to use sklearn then you don’t need to convert your data to a dataframe. You only need your data to have a proper shape (n_observations x n_features). In theory you could “unroll” the csd matrices into features but this will give you a lot of columns per observation (about n_channels * n_channels * n_frequencies / 2). To get the covariance matrix for given frequency you can use .get_data() method of CSD object. But bear in mind that covariance is symmetric, so using the whole matrix is redundant.
So if you really need to get all the csd values (of all frequencies) as one vector (one observation) then you can just use the contents of .data attribute.

1 Like

Thank you Mikolaj for your advice. That was very helpful. When I checked the computed CSD matrices, the output was similar to the output below. So I’m wondering what the variable j represent. Can you or anyone here help me by explaining what does it represent?

[ 3.82707986e-10-1.03289775e-12j, 3.39152512e-10-2.43430308e-11j]

Yes, the CSD, just like power spectral density is in complex values (to account for magnitude and phase), you can use np.abs(csd.data) to obtain the real values (this is done internally when plotting the csd for example).

1 Like

Thank you for the clarification. :blush: