Search code examples
pythonpandascsvjupyter-notebookanaconda3

“CSV file does not exist” for a filename in jupyter notebook


i have the following code.and i have the csv file located in the path but when i run the code it just says that the file dosent exist at all.i moved the code to diff locations and changed the path to the new one and i also changed the name of the file but it didnt worked.also i add ".csv" to the name of the file but no good came of it. here is the code:

import pandas as pd
import numpy as np
import csv
filename = ("C:\\Users\\Z\\pima-indians-diabetes.data.csv")
df1 = pd.read_csv(filename)
print(df1.head())'''

The error says

FileNotFoundError: [Errno 2] File C:\Users\Z\pima-indians-diabetes.data.csv does not exist: 'C:\\Users\\Z\\diabetes'

Solution

  • You need to give the *.csv file extension in your code. Replace

    filename = ("C:\\Users\\Z\\diabetes")
    

    with

    filename = "C:\\Users\\Z\\diabetes.csv"