From 98d98818cb7b84c2bba7f7e982b31f9021388257 Mon Sep 17 00:00:00 2001 From: wendtalexander Date: Sun, 15 Jan 2023 16:39:32 +0100 Subject: [PATCH] adding attributes from the pandas datafram to clas --- code/behavior.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/code/behavior.py b/code/behavior.py index b89a28a..dd32ef2 100644 --- a/code/behavior.py +++ b/code/behavior.py @@ -1,11 +1,41 @@ from pathlib import Path + +import numpy as np +from IPython import embed from pandas import read_csv + + class Behavior: + """Load behavior data from csv file as class attributes + Attributes + ---------- + behavior_type: + behavioral_category: + comment_start: + comment_stop: + dataframe: pandas dataframe with all the data + duration_s: + media_file: + observation_date: + observation_id: + start_s: + stop_s: + total_length: + """ + def __init__(self, datapath: str) -> None: csv_file = str(sorted(Path(datapath).glob('**/*.csv'))[0]) self.dataframe = read_csv(csv_file, delimiter=',') + for key in self.dataframe: + if ' ' in key: + new_key = key.replace(' ', '_') + if '(' in new_key: + new_key = new_key.replace('(', '') + new_key = new_key.replace(')', '') + new_key = new_key.lower() + setattr(self, new_key, np.array(self.dataframe[key])) def main(datapath: str):