Datasets:
import os | |
import tqdm | |
import csv | |
import pandas as pd | |
def get_darija_values(file): | |
"""This function reads the darija column from a csv file and returns | |
a generator of the values in the column. | |
""" | |
with open(file, 'r', encoding='utf-8') as infile: | |
reader = csv.reader(infile) | |
headers = next(reader) | |
for i, col in enumerate(headers): | |
if col=='darija': | |
break | |
for row in reader: | |
if row[i] != "": | |
yield row[i] | |
def ingest(input_data_path="ongoing/", output_data_path="data.csv"): | |
"""This function reads all the csv files in the input_data_path and extracts the | |
darija column from each file. It then saves the darija column in a csv file. | |
""" | |
full_df = pd.DataFrame() | |
text_list = [] | |
for file in tqdm.tqdm(os.listdir(input_data_path)): | |
if file.endswith(".csv"): | |
darija_txt = list(get_darija_values(input_data_path + file)) | |
text_list.extend(darija_txt) | |
full_df = pd.concat([full_df, pd.DataFrame(darija_txt, columns=["darija"])]) | |
full_df.to_csv(output_data_path, index=False) | |
print("Ingestion complete") | |
if __name__ == "__main__": | |
ingest("ongoing/") |