wyleejoongi 2021-11-20 17:44 采纳率: 40%
浏览 973
已结题

用pandas读取excel文件显示FileNotFoundError

#读取excel文件
import pandas as pd
import numpy as np
a=pd.read_excel("boston_housing_data.xlsx",usecols=range(0,10)) 
b=a.values  #提取其中的数据
c=a.describe()  #对数据进行统计描述
print(b)

运行结果

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-6-dd8426a0f057> in <module>
      3 import pandas as pd
      4 import numpy as np
----> 5 a=pd.read_excel("boston_housing_data.xlsx",usecols=range(0,10))  #提取第2列到第4列的数据
      6 b=a.values  #提取其中的数据
      7 c=a.describe()  #对数据进行统计描述

~\anaconda3\lib\site-packages\pandas\util\_decorators.py in wrapper(*args, **kwargs)
    297                 )
    298                 warnings.warn(msg, FutureWarning, stacklevel=stacklevel)
--> 299             return func(*args, **kwargs)
    300 
    301         return wrapper

~\anaconda3\lib\site-packages\pandas\io\excel\_base.py in read_excel(io, sheet_name, header, names, index_col, usecols, squeeze, dtype, engine, converters, true_values, false_values, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, parse_dates, date_parser, thousands, comment, skipfooter, convert_float, mangle_dupe_cols, storage_options)
    334     if not isinstance(io, ExcelFile):
    335         should_close = True
--> 336         io = ExcelFile(io, storage_options=storage_options, engine=engine)
    337     elif engine and engine != io.engine:
    338         raise ValueError(

~\anaconda3\lib\site-packages\pandas\io\excel\_base.py in __init__(self, path_or_buffer, engine, storage_options)
   1069                 ext = "xls"
   1070             else:
-> 1071                 ext = inspect_excel_format(
   1072                     content=path_or_buffer, storage_options=storage_options
   1073                 )

~\anaconda3\lib\site-packages\pandas\io\excel\_base.py in inspect_excel_format(path, content, storage_options)
    947     assert content_or_path is not None
    948 
--> 949     with get_handle(
    950         content_or_path, "rb", storage_options=storage_options, is_text=False
    951     ) as handle:

~\anaconda3\lib\site-packages\pandas\io\common.py in get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)
    649         else:
    650             # Binary mode
--> 651             handle = open(handle, ioargs.mode)
    652         handles.append(handle)
    653 

FileNotFoundError: [Errno 2] No such file or directory: 'boston_housing_data.xlsx'

1
​
1
​

  • 写回答

1条回答 默认 最新

  • 龙哥 毛哼哼爸 2021-11-21 09:44
    关注

    boston_housing_data.xlsx 这个文件的位置要写清楚。
    比如说,这个文件在 D盘,就写成a=pd.read_excel(r"D:\boston_housing_data.xlsx",usecols=range(0,10))

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 12月3日
  • 已采纳回答 11月25日
  • 创建了问题 11月20日

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)