Skip to content

Commit

Permalink
Create utils.py in etl directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Anita Caron authored Feb 22, 2024
1 parent 4932307 commit 4c19f1b
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/scripts/etl/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from pathlib import Path

import pandas as pd


def read(input, sep=","):
return pd.read_csv(input, encoding="latin-1", sep=sep)


def load(data: pd.DataFrame, file: Path):
data.to_csv(file, sep='\t', index=False)


def search_id(data, term_label):
filter_label = data[data["label"] == term_label.strip()]
if len(filter_label):
return filter_label['defined_class'].values[0]

return "NOTFOUND"


def generate_id(start_range, end_range):
for i in range(start_range, end_range, 1):
yield str(i)


def transform_id(term):
split = term.lower().split('a')
return f'FMA:{split[1]}'


def extract(data: pd.DataFrame, columns_extract: list) -> pd.DataFrame:
return data[columns_extract] # type: ignore

0 comments on commit 4c19f1b

Please sign in to comment.