How to Export a Clean CSV from Jupyter Notebook

You have cleaned your data in a pandas DataFrame and now you need to save it as a CSV file so you can upload it to GitHub. This takes one line of code.

The One Line You Need

At the end of your cleaning code, add this line. Replace df with whatever your DataFrame is called if it is different.

df.to_csv("retail_data_clean.csv", index=False)

index=False tells pandas not to include the row numbers (0, 1, 2...) as a column in your CSV. You almost always want this.

Where Does the File Save?

The file saves in the same folder as your Jupyter notebook. For example, if your notebook is at:

C:/Users/yourname/bampaa-project/analysis.ipynb

Then your clean CSV will be saved at:

C:/Users/yourname/bampaa-project/retail_data_clean.csv

How to Find the File

  • Open File Explorer (Windows) or Finder (Mac).
  • Navigate to the folder where your notebook is saved.
  • You should see retail_data_clean.csv listed there.
  • Open it in Excel or a text editor to confirm the data looks correct.

Specifying a Different Location

If you want to save it to a specific folder instead of the notebook's folder, pass the full path:

df.to_csv("C:/Users/yourname/Desktop/retail_data_clean.csv", index=False)

On Mac/Linux use forward slashes: /Users/yourname/Desktop/retail_data_clean.csv

Check Your File

Open the CSV to confirm it looks right. You should see your column headers on row 1 and clean data below - the issues you fixed should be gone.

Next Step

You now have your clean CSV ready. Head back to your Bampaa project and continue with saving your notebook file.

Try it yourself

Start with Level 1: print(), in your browser.

The first 5 levels are free · no sign-up needed