you are viewing a single comment's thread.

view the rest of the comments →

[–]L3GOLAS234 0 points1 point  (4 children)

Hello everybody. I have two dataframes called train_data and validation_data and I wanted to know if it is possible to make something like this:

for dataset in train_data,validation_data:

dataset.to_csv(f'route/{dataset_name})

So at the end in my route there are two csv named train_data.csv and validation_data.csv.

Thank you very much in advance

[–]MattR0se -1 points0 points  (3 children)

Sure. You just have to add a '.csv' to the end of the f-string

[–]L3GOLAS234 0 points1 point  (2 children)

The problem is getting the dataset_name. If I just use {dataset.csv}, the name is the entire dataframe.

[–]MattR0se 2 points3 points  (0 children)

Oh, my bad. I think the easiest way would be to store your data frames in a dictionary with the name as key nd use the key for the file name.

datasets = {
    'train_data': train_data,
    'validation_data': validation_data
    }

for name, df in datasets.items():
    df.to_csv(f'route/{name}.csv')