Yoshith Kotla
Yoshith Kotla

Reputation: 165

How to export data frame in Jupyter as a csv file

I have a data frame saved as df in a jupyter notebook, and i want to export it into a csv file on my desktop.

Upvotes: 5

Views: 72114

Answers (4)

Peter Hassaballah
Peter Hassaballah

Reputation: 1985

If you are using jupyter notebook online for example on google colab, then you need to specify the path within the to_csv parameters example:

df.to_csv('sample_data/myCSV.csv')

Upvotes: 0

Henry Nnonyelu
Henry Nnonyelu

Reputation: 64

I am assuming you have imported panda with pd and you're sure you have seen your Data Frame, df.
Use the below command:

df.to_csv(r'c:\program files\apps\')

Replace c:\program files\apps\ with your own path.
Note: the 'r' has to be there.

Upvotes: 0

imxitiz
imxitiz

Reputation: 3987

If you have data in pandas DataFrame then you can use .to_csv() function from pandas to export your data in CSV .

Here's how you can save data in desktop

df.to_csv("<path to desktop and filename>")

# If you just use file name then it will save CSV file in working directory.
# Example path : C:/Users/<>/Desktop/<file name>.csv

If you want to learn more about it you can visit official documentation.

Upvotes: 1

Cor
Cor

Reputation: 134

For a pandas data frame you can use df.to_csv('data.csv').

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_csv.html

Upvotes: 7

Related Questions