安裝ipython
pip install python
進(jìn)入python交互環(huán)境
$ 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]:
內(nèi)置json模塊可講json字符串轉(zhuǎn)換為python字典對象
- json.loads(json_str) #導(dǎo)入json字符串,生成字典對象
collections.Counter類
-
collections.Counter(list_value) 能獲取list列表里各元素的個(gè)數(shù),并生成一個(gè)counter對象
In [58]: counts = Counter(time_zones)In [59]: type(counts) Out[59]: collections.Counter In [60]: most_common(number)方法能獲取前number個(gè)元素的個(gè)數(shù)
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對元素進(jìn)行計(jì)數(shù)
- DAtaFrame是pandas中重要的數(shù)據(jù)結(jié)構(gòu),將數(shù)據(jù)表示為一個(gè)表格y