简体   繁体   English

在python 3.7中使用熊猫优化数据

[英]opoening data using pandas in python 3.7

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 : 嗨,我试图用python 3.7打开我使用pandas下载到我的文档的数据,但是它不起作用,这是我的代码:

    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:) thaks :)

It seems your issue is that your data file is not in the path of your python session. 看来您的问题是您的数据文件不在python会话的路径中。 There are a few ways to fix this. 有几种方法可以解决此问题。

  • First, your file has .user extension. 首先,您的文件具有.user扩展名。 I believe it should be a .csv extension for pd.read_csv(). 我认为它应该是pd.read_csv()的.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()函数的完整路径。

     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: 如果您使用的是ipython或jupyter笔记本,则可以使用cd path_to_file_folder命令导航到文件所在的文件夹,只需将文件名传递给该命令:

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

For more robust solutions check this discussion . 有关更强大的解决方案,请查看此讨论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM