赞
踩
主要内容有:
1.1 'utf-8' codec can't decode
从GitHub上下载的csv文件很多是raw中显示网页text格式的数据,然后右键另存为的数据,这些CSV文件看起来是逗号分隔的文件,但是内部数据的编码格式其实是带有BOM的utf-8的数据;
- 使用以下读取方式的时候,
- # -*- coding: utf-8 -*-
-
- 。。。。。。
-
- pre_train_sale = pd.read_csv('pre_train_sales_data.csv',encoding='utf-8')
- 会出现:
- UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc9 in position 0: invalid
1.2 pandas.read_csv() 报错OSError: Initializing from file failed
- 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')
-
-
- 这两种情况报错信息都是一样:
- Traceback (most recent call last):
- (报错细节不展示)
- File "pandas/_libs/parsers.pyx", line 720, in pandas._libs.parsers.TextReader._setup_parser_source
-
- OSError: Initializing from file failed
da4=pd.read_csv('F:数据源工程清单.csv',engine='python')
da3=pd.read_csv(open('F:4.0 居配工程监测2.0 数据源02.东京新居配工程清单.csv'))
2.1 h5py_init_.py:26:FutureWarning:
- h5py_init_.py:26:FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
- from ._conv import register_converters as _register_converters
2.2 ValueError: x and y must have same first dimension
2.3 VError: Found input variables with inconsistent numbers of samples: [73, 1]
2.4 报错信息ax = axes if axes else plt.gca() ValueError: The truth value of an array with more than one ele
2.5 异类数据操作错误:TypeError: unsupported operand type(s) for -: 'str' and 'int'
- #代码如下
- import urllib.request
- import urllib.parse
-
- #发送get请求,在浏览器输入接口url豆瓣地址,浏览器会直接返回该信息
- url_douban='https://movie.douban.com/j/chart/top_list?type=5&interval_id=100%3A90&action=&'
-
- #start=40&limit=20'
- #分析接口既是url
- #start limit 在豆瓣网站中start表示影片从第40部开始计算,影片数量限制在20部,也就是在第60部结束
- page= int(input('请输入想要的第几页数据:'))
- # 请输入想要的第几页数据:0
- Traceback (most recent call last):
- File “1-post2.py”, line 16, in
- ‘start’:(page-1)*number,
- TypeError: unsupported operand type(s) for -: ‘str’ and ‘int’
3.1 复制代码缩进问题:TabError: inconsistent use of tabs and spaces in indentation
TabError: inconsistent use of tabs and spaces in indentation
3.2 列表索引问题:TypeError: list indices must be integers or slices, not str
TypeError: list indices must be integers or slices, not str
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。