read_csv报错Initializing from file failed
Failed 报错 File from Read csv
2023-09-11 14:21:25 时间
Python版本:Python 3.6
pandas.read_csv() 报错 OSError: Initializing from file failed,一般由两种情况引起:一种是函数参数为路径而非文件名称,另一种是函数参数带有中文。
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 4 09:44:36 2018
@author: wfxu
"""
import pandas as pd
da1=pd.read_csv('F:\\数据源')
da2=pd.read_csv('F:\\2.0 数据源\\工程清单.csv')12345678
这两种情况报错信息都是一样:
Traceback (most recent call last):
(报错细节不展示)
File "pandas/_libs/parsers.pyx", line 720, in pandas._libs.parsers.TextReader._setup_parser_source
OSError: Initializing from file failed12345
对于第一种情况很简单,原因就是没有把文件名称放到路径的后面,把文件名称添加到路径后面就可以了。还可以在代码中把文件夹切换到目标文件所在文件夹,过程太繁杂,不喜欢也不推荐,所以就不做展示了。
第二种情况,即使路径、文件名都完整,还是报错的原因是这个参数中有中文,但是Python3不是已经支持中文了吗?参考了错误原因和pandas的源码,发现调用pandas的read_csv()方法时,默认使用C engine作为parser engine,而当文件名中含有中文的时候,用C engine在部分情况下就会出错。所以在调用read_csv()方法时指定engine为Python就可以解决问题了。
da4=pd.read_csv('F:\\数据源\\工程清单.csv',engine='python')1
对于第二种情况还有另外一种解决方法,就是使员工open函数打开文件,再取访问里面的数据:
da3=pd.read_csv(open('F:\\4.0 居配工程监测\\2.0 数据源\\02.南京新居配工程清单.csv'))1
好了这个报错的原因都了解了,解决方法也很简单粗暴,是不是很简短简单!
来源https://blog.csdn.net/qq_35318838/article/details/80564938
相关文章
- Centos7 系统启动docker报错 inotify add watch failed
- chroot: failed to run command ‘/bin/bash’: No such file or directory
- org.springframework.jdbc.CannotGetJdbcConnectionException Failed to obtain JDBC Connection
- MySQL启动报错: Failed to start LSB start and stop MySQL
- PyCharm failed to create JVM
- SpringBoot启动报错:org.apache.catalina.LifecycleException: Protocol handler start failed
- git遇到error: RPC failed; curl 18 transfer closed with outstanding read data remaining fatal: The remote end hung up unexpectedly fatal: early EOF fatal: index-pack failed failed怎么办?
- Nginx 报错: nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory) 的解决方法
- failed to create pid file /var/run/rsyncd.pid: File exists报错
- Failed to get D-Bus connection: Operation not permitted解决
- TPC-DS tools生成数据:ERROR: Failed to open output file! File print.c Line: 490
- 解决connect() failed (111: Connection refused) while connecting to upstream
- PySe-016-Requests 访问 HTTPS 网站报错解决方法:SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)
- anaconda安装pytorch过程中报错:Collecting package metadata (current_repodata.json): failed的问题解决
- [Vue warn]: Failed to mount component: template or render function not defined.解决方案
- Ubuntu系统中CUDA套件nvvp启动后报错Failed to load module "canberra-gtk-module"
- MindSpore分布式并行训练 (GPU-Docker)mindspore—1.2.1—gpu—docker版本运行报错,Failed to init nccl communicator for group,init nccl communicator for group nccl_world_group
- Stack Overflow requires external JavaScript from another domain, which is blocked or failed to load.
- 【HMS Core】升级SDK报错app_id failed: java.io.FileNotFoundException: agconnect-services.json
- docker Failed to get D-Bus connection 报错 docker run -e MYVAR1 --env MYVAR2=foo --env-file ./env.list ubuntu bash
- 使用SourceTree管理Unity工程推送报错 “ RPC failed; curl 55 Send failure: Connection was aborted“
- SQL Server SSPI handshake failed报错,sql server修改windows账户密码的影响,sql server订阅发布客户端访问一直报错
- sql server代理服务无法启动(SQL Agent):OpenSQLServerInstanceRegKey:GetRegKeyAccessMask failed (reason: 2).
- 【Android Studio报错】:Failed to read key AndroidDebugKey from store “C:Users13181.androiddebug.keys
- 【安卓-疑难杂症】:你的主机中的软件中止了一个已建立的连接 and The application could not be installed: INSTALL_FAILED_USER_RESTRI
- 解决只读模式U盘保护格式化或者dd写报错:ERROR: failed to open ‘/dev/sdb‘ in read-write mode: Read-only file system.
- IIS 报错 Cannot open database "test4" requested by the login. The login failed. Login failed for user 'IIS APPPOOLtest1'.
- send message failed [channel: Netty4TcpChanne GC (Allocation Failure, ParNew Desired survivor size
- FTP客户端连接失败,提示“530 Authentication failed” (原)
- 解决浏览器console控制台报错 : Failed to load resource: net::ERR_SSL_PROTOCOL_ERROR(SSL协议错误)