-1

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'

3 Answers3

1

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

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

with

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

Few steps to check whether the file indeed exists:

  • Open a Command Prompt (Click Start and type cmd)
  • Type this command dir C:\Users\Z\pima-indians-diabetes.*
    • This will clearly show if the file in question really exists.
    • It might not be there at all.
    • Or it might be named C:\Users\Z\diabetes.csv.csv.
    • Latter can happen when saving a file with Save As and typing my-file.csv for the file name, unaware that the application being used also adds the extension .csv, so now there are two of those.
  • Here is the expected command output for an existing file with correct name:
C:\Users\Z>dir C:\Users\Z\pima-indians-diabetes.*
         983 pima-indians-diabetes.data.csv
               1 File(s)            983 bytes
               0 Dir(s)  220,040,663,040 bytes free
  • tnx alot dear reverent Doron. yes as u also mentioned my problem was the false name as it was named C:\Users\Z\diabetes.csv.csv – Beryl Amend Nov 13 '20 at 17:15
-1

remove '.' from your filename. I think it is effecting your file format

phoenix
  • 298
  • 1
  • 10