Py第六问 py3.5学习笔记<利用python进行数据分析>
来源:互联网 发布:生命探测软件 编辑:程序博客网 时间:2024/06/16 20:13
2016年9月22日
第二章
来自bit.ly的1.usa.gov数据
import jsonpath = '/home/python3/data/pydata-book-master/ch02/usagov_bitly_data2012-03-16-1331923249.txt'#records = [json.loads(line) for line in open(path)]with open(path) as jsonfile: data = json.load(jsonfile)
问题1:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 228171: ordinal not in range(128)
解决
Python 3 decodes text files when reading. The default encoding is taken from locale.getpreferredencoding(False)
, which evidently for your setup returns 'ASCII'
. See the open()
function documenation:
In text mode, if encoding is not specified the encoding used is platform dependent:
locale.getpreferredencoding(False)
is called to get the current locale encoding.
Instead of relying on a system setting, you should open your text files using an explicit codec:
currentFile = open(filename, 'rt', encoding='latin1')
where you set the encoding
parameter to match the file you are reading.
Python 3 supports UTF-8 as the default for source code.
You may want to read up on Python 3 and Unicode in the Unicode HOWTO, which explains both about source code encoding and reading and writing Unicode data.
import jsonpath = '/home/python3/data/pydata-book-master/ch02/usagov_bitly_data2012-03-16-1331923249.txt'#records = [json.loads(line) for line in open(path)]with open(path) as jsonfile: data = json.load(jsonfile.encoding("latin1"))问题二
TypeError: 'str' object is not callable
- Py第六问 py3.5学习笔记<利用python进行数据分析>
- 利用Python进行数据分析 学习笔记
- 《利用Python进行数据分析》学习笔记ch04(5)
- 《利用Python 进行数据分析》 - 笔记(5)
- 利用python进行数据分析学习笔记—python基础知识
- 《利用python进行数据分析》学习笔记(一)
- 利用python进行数据分析(学习笔记)
- 《利用Python进行数据分析》第二章-学习笔记
- 《利用python进行数据分析》学习笔记(一)
- 《利用python进行数据分析》学习笔记(二)
- 《利用python进行数据分析》学习笔记(三)
- 《利用python进行数据分析》学习笔记(四)
- 《利用python进行数据分析》学习笔记(六)
- 《利用Python进行数据分析》学习笔记ch02-1(1)
- 《利用Python进行数据分析》学习笔记ch02-2(2)
- 《利用Python进行数据分析》学习笔记ch02-3(3)
- 《利用Python进行数据分析》学习笔记ch03(4)
- 《利用Python进行数据分析》学习笔记ch05(6)
- [Android知识体系]之四大组件:activity(生命周期管理)
- loopback学习(1)--简介
- cocoapods 提示:无法添加与URL源
- The properties of Impulse Function
- linux搭建ngnix环境
- Py第六问 py3.5学习笔记<利用python进行数据分析>
- GTest测试私有函数
- yarn中的cgroup调度
- CSS:去除点击链接和按钮时出现的虚线框
- 温故知新(六):排序介绍
- 想在公司推广Golang吗-Golang之美
- C51单片机实现六位数码管时钟
- 禅道管理系统的定时任务 代码
- thinkphp跨库操作代码实例