Reading from CSV file

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 guys,

I encountered a problem to convert csv file and use it as a dataset. This file contains 25 columns (20 eeg channels, ecg, R, GSR, TimeSecs, and Event), and 1037788 rows. I have read the csv file using read_csv() function and then created 25 channels names and types where I used the types eeg, ecg, and misc and then defined the sampling frequency as 256. Then I created the info object and tried to pass the 1037788 data to the channels names but got error message saying it doesn’t match. Am I supposed to create 1037788 channels to make my code works? Please have a look at the code below.

User_frame = pd.read_csv("C:/Users/Datasets/5/5/5_LOFT.csv", sep=',', index_col=0) 
data= pd.DataFrame.to_numpy(User_frame, dtype= np.float64)

# assigning the channel type when initializing the Info object
ch_names = ['TimeSecs misc', 'EEG_FP1 eeg', 'EEG_F7 eeg', 'EEG_F8 eeg', 'EEG_T4 eeg', 
'EEG_T6 eeg', 'EEG_T5 eeg', 'EEG_T3 eeg', 'EEG_FP2 eeg', 'EEG_O1 eeg', 'EEG_P3 eeg', 
'EEG_Pz eeg', 'EEG_F3 eeg', 'EEG_Fz eeg', 'EEG_F4 eeg', 'EEG_C4 eeg', 'EEG_P4 eeg', 
'EEG_POz eeg', 'EEG_C3 eeg', 'EEG_Cz eeg', 'EEG_O2 eeg', 'ECG ecg', 'R misc', 'GSR misc', 
'Event misc']

ch_types = ['misc', 'eeg', 'eeg', 'eeg', 'eeg', 'eeg', 
            'eeg', 'eeg', 'eeg', 'eeg', 'eeg', 'eeg', 
            'eeg', 'eeg', 'eeg', 'eeg', 'eeg', 'eeg', 
            'eeg', 'eeg', 'eeg', 'ecg', 'misc', 'misc', 'misc']

sampling_freq = 256  # in Hertz

info = mne.create_info(ch_names= ch_names, ch_types= ch_types, sfreq= sampling_freq)

User_raw = mne.io.RawArray(data, info)

ValueError: len(data) (1037788) does not match len(info["ch_names"]) (25)

Hello @ibra332 and welcome to the forum! You need to transpose the data, as MNE expects one channel per row, and one time point per column. Your data seems to have it the other way around. So you would need to do

data = User_frame.transpose().to_numpy()

Thank you Richard. Worked with me