File size: 1,127 Bytes
8af1909
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pandas as pd
import xlsxwriter
from sklearn.model_selection import train_test_split

# Load your prepared dataset
file_path = '/Users/colestephens/Desktop/CodeFolders/ML_Dataset_Curation_Project/Sanitized_data/homo_hydrogenation.csv'  # Path to your sanitized CSV
df = pd.read_csv(file_path)

# Number of splits you want to create
n_splits = 5

# Initialize a writer to write multiple sheets
output_file = '/Users/colestephens/Desktop/CodeFolders/ML_Dataset_Curation_Project/Split_data/homo_hydrogenation.xlsx'

with pd.ExcelWriter(output_file, engine='xlsxwriter') as writer:
    for split_index in range(n_splits):
        # Perform the train-test split
        train_df, test_df = train_test_split(df, test_size=0.2, random_state=split_index)

        # Write each train and test split to separate sheets
        train_sheet_name = f'train_split_{split_index}'
        test_sheet_name = f'test_split_{split_index}'

        train_df.to_excel(writer, sheet_name=train_sheet_name, index=False)
        test_df.to_excel(writer, sheet_name=test_sheet_name, index=False)

print(f'Train-test splits saved to {output_file}')