Reputation: 23
I saved csv file in (C:/Users/kgu/PycharmProjects/untitled1/test1.py). named as testdata.csv
my code is :
import csv
f=open('testdata.csv','r',encoding='utf-8')
And the error message is here :
C:\Users\kgu\Anaconda3\python.exe
C:/Users/kgu/PycharmProjects/untitled1/test1.py
Traceback (most recent call last):
File "C:/Users/kgu/PycharmProjects/untitled1/test1.py", line 3, in <module>
f=open('testdata.csv','r',encoding='utf-8')
FileNotFoundError: [Errno 2] No such file or directory: 'testdata.csv'
Process finished with exit code 1
I did save the testdata.csv
in the python project folder.
I don't know what is wrong in it.
Upvotes: 2
Views: 1766
Reputation: 3634
If you use Pandas, you can try:
import pandas as pd
filepath = "/yourfilepath/yourfile.csv"
# check your sep (";" , "," ...)
f = pd.read_csv(filepath, encoding="utf-8", sep="yoursep")
Upvotes: 1
Reputation: 216
You could do it like this - if you are in the right working directory:
with open(testdata.csv', 'rb') as csvfile:
data = [x for x in csv.reader(csvfile, delimiter='yourdelimiter')]
Upvotes: 0