简体   繁体   English

我无法使用 Pandas 在 python 上打开我的 Excel 文件

[英]I can't open my Excel file on python, using pandas

I can't open my Excel file on python, and I think I've tried all the options out there.我无法在 python 上打开我的 Excel 文件,我想我已经尝试了所有选项。

I am using a mac, and I don't think I typed in the path wrong..?我使用的是 mac,我认为我输入的路径没有错误..? I've installed xlrd and openpyxl as well, but I don't think it's the reader problem...我也安装了xlrdopenpyxl ,但我不认为这是阅读器的问题......

import pandas as pd

data = pd.ExcelFile("/User/[username]/desktop/assignment3/titanic3.xls")

and I get this error:我收到这个错误:

在此处输入图片说明

You should replace [username] with your real username.您应该将[username]替换为您的真实用户名。

To get your username, enter whoami in a terminal (Not python, but a shell terminal).要获取您的用户名,请在终端(不是 python,而是 shell 终端)中输入whoami

To open a terminal on Mac OS X, type + space to open Spotlight, then type terminal to open a terminal.要在 Mac OS X 上打开终端,请键入 +空格以打开 Spotlight,然后键入terminal以打开终端。

Then replace the returned value of whoami in your jupyter command.然后在您的 jupyter 命令中替换whoami的返回值。

From what I have seen, it should be cynthiaoh就我所见,应该是cynthiaoh

import pandas as pd
data = pd.ExcelFile("/User/cynthiaoh/Desktop/assignment3/titanic3.xls")

If this does not work, it means:如果这不起作用,则意味着:

  • you have a camel case problem: is it desktop or Desktop您有驼峰式保护套问题:是desktop还是Desktop
  • the Excel file you want to load is not located in the directory you think it is.您要加载的Excel文件不在您认为的目录中。

试试这个

pd.read_excel(r'file_path.xls')

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

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