Skip to content

Instantly share code, notes, and snippets.

@simplymathematics
Created April 6, 2019 23:45
Show Gist options
  • Save simplymathematics/cd062bd5e8ea037459410a4e5bab4df0 to your computer and use it in GitHub Desktop.
Save simplymathematics/cd062bd5e8ea037459410a4e5bab4df0 to your computer and use it in GitHub Desktop.
Cleans some eeg data
import pandas as pd
import numpy as np
import sys
import argparse
import time
def eeg_clean(file_input, file_output):
data1 = pd.read_csv(file_input, sep = ';')
data1.dropna(inplace = True)
raw = str(data1['MNI152']).replace("[", "")
raw = str(raw).replace("]", "")
raw = raw.split("\n")[:][:]
for i in range(len(raw)):
raw[i] = raw[i][7:]
raw[i] = raw[i].lstrip()
raw[i] = raw[i].rstrip()
raw[i] = raw[i].strip()
raw[i] = raw[i].split(" ")
while '' in raw[i]:
raw[i].remove('')
clean_mni = pd.DataFrame(raw)
clean_mni = clean_mni.drop(columns = [3,4])
raw = str(data1['RAS-Slicer']).replace("[", "")
raw = str(raw).replace("]", "")
raw = raw.split("\n")[:][:]
for i in range(len(raw)):
raw[i] = raw[i][7:]
raw[i] = raw[i].lstrip()
raw[i] = raw[i].rstrip()
raw[i] = raw[i].strip()
raw[i] = raw[i].split(" ")
while '' in raw[i]:
raw[i].remove('')
clean_ras = pd.DataFrame(raw)
clean_ras = clean_ras.drop(columns = [3,4])
big = pd.DataFrame()
big['Electrodes'] = data1['Electrodes']
big['RAS-1'] = clean_ras[0]
big['RAS-2'] = clean_ras[1]
big['RAS-3'] = clean_ras[2]
big['MNI-1'] = clean_mni[0]
big['MNI-2'] = clean_mni[1]
big['MNI-3'] = clean_mni[2]
big['Label'] = data1['ASEG_Region']
timestamp = str(round(time.time()))
big['Patient_ID'] = timestamp
file_output_patient = str(file_output +"_" + timestamp + ".csv" )
big.to_csv(file_output_patient)
if __name__ == "__main__":
file_input = "example_coordinates.csv"
file_output = "cleaned"
eeg_clean(file_input, file_output)
# To import this file, add
#
# import eeg_clean.py
#
# into a new jupyter notebook
#
# To use:
# use the function with
# eeg_clean(input, ouput)
# make sure to enter both an input file and a output file as a string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment