学习笔记-第二章
2016-10-16 本文已影响0人
幽谷听泉
安装ipython
pip install python
进入python交互环境
$ ipython
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
Type "copyright", "credits" or "license" for more information.
IPython 5.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]:
内置json模块可讲json字符串转换为python字典对象
- json.loads(json_str) #导入json字符串,生成字典对象
collections.Counter类
-
collections.Counter(list_value) 能获取list列表里各元素的个数,并生成一个counter对象
In [58]: counts = Counter(time_zones)In [59]: type(counts) Out[59]: collections.Counter In [60]:
-
most_common(number)方法能获取前number个元素的个数
In [60]: counts.most_common(10)
Out[60]:
[(u'America/New_York', 1251),
(u'', 521),
(u'America/Chicago', 400),
(u'America/Los_Angeles', 382),
(u'America/Denver', 191),
(u'Europe/London', 74),
(u'Asia/Tokyo', 37),
(u'Pacific/Honolulu', 36),
(u'Europe/Madrid', 35),
(u'America/Sao_Paulo', 33)]
In [61]:
用pandas对元素进行计数
- DAtaFrame是pandas中重要的数据结构,将数据表示为一个表格y