-
Notifications
You must be signed in to change notification settings - Fork 0
/
5__merge_dataset.py
79 lines (57 loc) · 2.51 KB
/
5__merge_dataset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import pandas as pd
# Load the dataset
df = pd.read_csv('training_dataset_use')
# Group the documents by level and concatenate the descriptions
grouped_df = df.groupby('eqf_level_id')['description'].apply('\n'.join).reset_index()
# Iterate over the groups and save each level's document to a separate file
for _, row in grouped_df.iterrows():
level_id = row['eqf_level_id']
description = row['description']
# Save the level document to a separate file
filename = f'{level_id}'
with open(filename, 'w') as file:
file.write(description)
print(f'Saved level {level_id} document to {filename}')
#import pandas as pd
# Create an empty DataFrame
merged_df = pd.DataFrame(columns=['eqf_level_id', 'description'])
# Iterate over each document
for doc_num in range(1, 9):
# Read the document content
with open(f'{doc_num}', 'r') as file:
content = file.read()
# Create a DataFrame for the current document
doc_df = pd.DataFrame({'eqf_level_id': [doc_num], 'description': [content]})
# Append the document DataFrame to the merged DataFrame
merged_df = merged_df.append(doc_df, ignore_index=True)
# Save the merged DataFrame to a CSV file
merged_df.to_csv('merged_training.txt', index=False)
# SECOND TRAINING FOR SECOND DEV DATA
import pandas as pd
# Load the dataset
df = pd.read_csv('sec_training_dataset_use')
# Group the documents by level and concatenate the descriptions
grouped_df = df.groupby('eqf_level_id')['description'].apply('\n'.join).reset_index()
# Iterate over the groups and save each level's document to a separate file
for _, row in grouped_df.iterrows():
level_id = row['eqf_level_id']
description = row['description']
# Save the level document to a separate file
filename = f'{level_id}'
with open(filename, 'w') as file:
file.write(description)
print(f'Saved level {level_id} document to {filename}')
#import pandas as pd
# Create an empty DataFrame
merged_df = pd.DataFrame(columns=['eqf_level_id', 'description'])
# Iterate over each document
for doc_num in range(1, 9):
# Read the document content
with open(f'{doc_num}', 'r') as file:
content = file.read()
# Create a DataFrame for the current document
doc_df = pd.DataFrame({'eqf_level_id': [doc_num], 'description': [content]})
# Append the document DataFrame to the merged DataFrame
merged_df = merged_df.append(doc_df, ignore_index=True)
# Save the merged DataFrame to a CSV file
merged_df.to_csv('sec_merged_training.txt', index=False)