Saving a DataFrame to CSV to a Specific Location
Python
In this example we save a Pandas dataframe to csv from a script located in path project_folder/src to path project_folder/data. We use os.path to get the path of the folder two levels above the script and join this to the destination folder and filename where we want to store our csv.
1| import os.path as path 2| import pandas as pd 3| 4| train_path = path.abspath(path.join(__file__ ,'../..','data/train.csv')) 5| train.to_csv(train_path,index=False)
149
132
127
119