Datasets:
Delete alignments/clean_up_csv.py
Browse files- alignments/clean_up_csv.py +0 -42
alignments/clean_up_csv.py
DELETED
@@ -1,42 +0,0 @@
|
|
1 |
-
import pandas as pd
|
2 |
-
import os
|
3 |
-
|
4 |
-
# Read the original CSV
|
5 |
-
alignment = pd.read_csv("alignments/all_de_en_alligned.csv", index_col=0)
|
6 |
-
|
7 |
-
# Create mapping of book numbers to English folder names
|
8 |
-
en_folder_map = {}
|
9 |
-
for folder in os.listdir("EN"):
|
10 |
-
book_id = folder.split('.')[0]
|
11 |
-
en_folder_map[book_id] = folder
|
12 |
-
|
13 |
-
# Function to construct full German audio path
|
14 |
-
def get_de_path(row):
|
15 |
-
if "67" in row['book']:
|
16 |
-
return os.path.join("DE","67.frankenstein_de_1211_librivox_newly_alligned", "sentence_level_audio", row['DE_audio'])
|
17 |
-
return os.path.join("DE", row['book'], "sentence_level_audio", row['DE_audio'])
|
18 |
-
|
19 |
-
# Function to construct full English audio path
|
20 |
-
def get_en_path(row):
|
21 |
-
book_id = str(row['book_id'])
|
22 |
-
if book_id in en_folder_map:
|
23 |
-
return os.path.join("EN", en_folder_map[book_id], "sentence_level_audio", row['EN_audio'] + ".wav")
|
24 |
-
return None
|
25 |
-
|
26 |
-
# Update paths in the DataFrame
|
27 |
-
alignment['DE_audio'] = alignment.apply(get_de_path, axis=1)
|
28 |
-
alignment['EN_audio'] = alignment.apply(get_en_path, axis=1)
|
29 |
-
|
30 |
-
# Drop the 'book' column since paths are now complete
|
31 |
-
alignment = alignment.drop('book', axis=1)
|
32 |
-
|
33 |
-
# Drop rows where EN_audio path couldn't be constructed (book_id not found)
|
34 |
-
alignment = alignment.dropna(subset=['EN_audio'])
|
35 |
-
|
36 |
-
# Save the cleaned up csv
|
37 |
-
alignment.to_csv("alignments/all_de_en_alligned_cleaned.csv", index=False)
|
38 |
-
|
39 |
-
print(f"Saved cleaned CSV with {len(alignment)} rows")
|
40 |
-
print("\nFirst few rows of cleaned CSV:")
|
41 |
-
print(alignment.head())
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|