shaik anish mib
shaik anish mib

Reputation: 1

How do i read a csv file into a pandas dataframe which is stored in my local storage in jupyter lab

The following is my code to read my CSV file stored in my project folder into the pandas data frame in jupyter lab.

      df=pd.read_csv(r"C:\Users\u s e r\my first project\news.csv")
      #Get shape and head
      df.shape
      df.head()

the below is the error I'm getting while doing so

            pandas/_libs/parsers.pyx in 
            pandas._libs.parsers.TextReader.__cinit__()

            pandas/_libs/parsers.pyx in 
            pandas._libs.parsers.TextReader._setup_parser_source()

            FileNotFoundError: [Errno 2] File C:\Users\u s e r\my first 
            project\news.csv does not exist: 'C:\\Users\\u s e r\\my 
            first project\\news.csv'

I've tried using r subscript and saving the path in a variable .but nothing seems to be working.

what should I do?

Upvotes: 0

Views: 1342

Answers (2)

John Calchon
John Calchon

Reputation: 127

Put the *.csv file in the root of the project, and then run the following:

df=pd.read_csv("news.csv")

You should avoid any problem regarding wrong paths, slashes/backslashes and/or empty chars, and it should work regardless the operative system which seems to be windows in your case.

Upvotes: 3

yellowFlower
yellowFlower

Reputation: 37

Start with rename your folders, replace spaces to '_' then try to read your file again.

Upvotes: 0

Related Questions