1 Upvote

Saving a DataFrame to CSV to a Specific Location

Python
Import and Export

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.

import os.path as path
import pandas as pd

train_path = path.abspath(path.join(__file__ ,'../..','data/train.csv'))
train.to_csv(train_path,index=False)

By analyseup - Last Updated Sept. 30, 2021, 2:34 p.m.

Did you find this snippet useful?

Sign up to bookmark this in your snippet library

COMMENTS
RELATED SNIPPETS
Top Contributors
103
100