0

hi i tried to open some data that i downloaded to my documents using pandas with python 3.7 but it doesnt work this is my code :

    import pandas as pd
    users=pd.read_csv("ml-100k/u.user",sep="|",names=["User ID","Age","Gender", 
    "aciation" ,"zipcode"])
    user.head()

the eror is :

    FileNotFoundError: File b'ml-100k/u.user' does not exist

how can it be that the file doesnt exist if i downloaded it ? thaks:)

  • I'm not sure why you're getting a byte string, but that's a relative path so it matters what directory you're in when you run that code – roganjosh Sep 01 '18 at 13:36

1 Answers1

0

It seems your issue is that your data file is not in the path of your python session. There are a few ways to fix this.

  • First, your file has .user extension. I believe it should be a .csv extension for pd.read_csv(). Rename the file to make sure the extension and the name of the file are correct. I also advise to make the filename code friendly, substitute whitespaces for _ or - and remove non-alphanumeric characters #*/().

  • One solution is to provide the full path to the pd.read_csv() function.

    pd.read_csv("/home/user/folder/file_name.csv",
                sep="|",names=["User ID","Age","Gender","aciation" ,"zipcode"])
    
  • If you are using ipython or jupyter notebook you can navigate to the same folder where your file is at with cd path_to_file_folder command and simply pass the file name to the command:

    pd.read_csv("file_name.csv",sep="|",
                names=["User ID","Age","Gender","aciation" ,"zipcode"])
    

For more robust solutions check this discussion.

Frâncio Rodrigues
  • 2,190
  • 3
  • 21
  • 30