Jim Hoopes
Jim Hoopes

Reputation: 1

Save a dataframe to a new csv file in a new directory

I am trying to take some new data that I have created from some old data and I want to save the new data in a different directory separate from the original directory from where I got the original data. I believe I have the correct data path but I don't think I am using the correct method being called to both create the csv and put it in the newly created directory. I have the code what I was suggested:

#create the appropriate data path
datapath = '../data'
#save the dataframe as a csv file in a new directory
save_file(ski_data, 'ski_data_cleaned.csv', datapath)

I get an error: NameError: name 'save_file' is not defined

I was understanding the 'save_file' was the method and I'm not sure how to include the 'datapath' in other methods?

Upvotes: 0

Views: 2524

Answers (1)

Sivaram Rasathurai
Sivaram Rasathurai

Reputation: 6333

try below one: Call to_csv method on your dataframe. you need to pass the CSV file path as an argument for the method.

ski_data.to_csv("../data/ski_data_cleaned.csv") 

If you need to save without headers then use the following one.

ski_data.to_csv("../data/ski_data_cleaned.csv", header=False, index=False) 

To save a specific location

#For windows
ski_data.to_csv(r"C:\Users\Admin\Desktop\data\ski_data_cleaned.csv") 

Check out the official site for more details.

Upvotes: 2

Related Questions