pythonpandasjupyter-notebook

I am trying to import data to Python, I am using Pandas and Jupyter Notebook


import numpy as np
import pandas as pd 

df = pd.read_csv('spotify_data.csv')
​
df.head()

Getting an error

FileNotFoundError: [Errno 2] No such file or directory: 'spotify_data.csv'

I have that dataset downloaded to my computer and I see it is showing in the Jupyter Notebook, but I don't have any idea why is not working. I am been looking into other similar cases, but cant see to find the answer.


Solution

  • That error usually means Python can't find the file in the location it's looking at, even if it looks like it's "there" in Jupyter Notebook.

    A couple of things to check:

    1. Is the notebook in the same folder as the CSV file?
      If not, you’ll need to either move the CSV to the same folder or use the full file path.

    2. Double-check the filename
      Make sure there are no typos, extra spaces, or different capitalization. File names are case-sensitive on some systems.

    3. Double-check the working directory
      In a code cell, run this to check what folder your notebook is currently running in:

      import os os.getcwd() 
      

      This will show the current working directory. Make sure your CSV is there, or update the path accordingly.