how to load csv data in Python 3 using Jupyter
I am trying to import data from a csv file using Jupyter. I am new to Python. It works fine in IDLE, but not in Jupyter. import csv with open("mpg.txt","r") as mpgFile: mpgFileReader = csv.reader(mpgFile) mpgList =  for row in mpgFileReader: if len (row)!=0: mpgList = mpgList + [row] mpgFile.close() print(mpgList) This is the error I receive --------------------------------------------------------------------------- FileNotFoundError Traceback (most recent call last) <ipython-input-60-42823a11b1d0> in <module>() 1 import csv ----> 2 with open("mpg.txt","r") as mpgFile: 3 mpgFileReader = csv.reader(mpgFile) 4 mpgList =  5 for row in mpgFileReader: FileNotFoundError: [Errno 2] No such file or directory: 'mpg.txt' I also tried to specify the full path of the file: "C:\Users\serdi\Documents\Test\mpg.txt" But then it gives me another error: File "<ipython-input-61-fed3bca4876a>", line 2 with open("C:\Users\serdi\Documents\Test\mpg.txt","r") as mpgFile: ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
The original problem is likely as you surmised, namely the path is incorrect. However the second error is due to the \ in the "C:\Users\serdi\Documents\Test\mpg.txt" The \ is an escape. There are at least three alternatives. Use a raw string: with open(r"C:\Users\serdi\Documents\Test\mpg.txt","r") as mpgFile: note the r in front of the string. Escape the \: with open("C:\\Users\\serdi\\Documents\\Test\\mpg.txt","r") as mpgFile: Use '/' instead of \: with open("C:/Users/serdi/Documents/Test/mpg.txt","r") as mpgFile:
Building logic gates
Return all tuple only from list
Reassign rows and columns in Python csv
How to check raw_input answers inside if-statements
how does one define a nullary function in python?
Sympy, plotting geometric entities yields either ImportError: no module named 'plot' or AttributeError: 'Circle' object has no attribute 'is_3D'
Select first row that meets certain condition
Splitting longer patterns using regex without losing characters Python 3+
Using python sdist to create a package that includes generated files in the build directory
Any elegant way to add a method to an existing object in python?
Setting cookies for static files using bottle.py
Python/Feedparser: reading RSS feed fails
How to generate a Torrent Magnet URI from a directory?
Python/Kivy camera widget error with opencv
Python3 - When exactly do you need to prepend “self._” to variable declarations within class methods? [duplicate]
how to tell python 3 to skip over non-digit characters from a csv file