Python庫函數(shù)介紹:http://www.runoob.com/python/python-socket.html
python:https://yiyibooks.cn/xx/python_352/library/ssl.html
1.用Python獲取數(shù)據(jù)(抓取網(wǎng)頁)
- urllib
- urllib2
- httplib
- httplib2
- 抓取網(wǎng)頁
- import urllib
- urilib.request.urlopen()
- f.read(),f.readline(),f.close()
3 . 對(duì)象身份比較:
- is ,is not
序列類型轉(zhuǎn)換工廠函數(shù)
list(),str(),unicode(),basestring(),tuple()可用內(nèi)建函數(shù)
enumerate(),sorted(),reversed(),len(),max(),sum(),min(),zip()
- enumerate 函數(shù)用于遍歷序列中的元素以及它們的下標(biāo):
for i,j in enumerate(('a','b','c')):
print i,j
0 a
1 b
2 c
6.字符串
- str.istitle()是標(biāo)題格式嗎
列表
list.sort(func=none,key=none,reverse=false) --key=len是按照列表的長(zhǎng)度進(jìn)行排序創(chuàng)建字典:
- dict(info) info=[('wang',3000),('li',2340)]
- aDict={}.fromkeys(('wang','ni'),3000)
工資默認(rèn)值是3000,fromkeys(key值呛梆,默認(rèn)鍵值)
- zip()函數(shù):
- zip()是Python的一個(gè)內(nèi)建函數(shù)翼闽,它接受一系列可迭代的對(duì)象作為參數(shù)呈宇,將對(duì)象中對(duì)應(yīng)的元素打包成一個(gè)個(gè)tuple(元組),然后返回由這些tuples組成的list(列表)阳啥。若傳入?yún)?shù)的長(zhǎng)度不等晨川,則返回list的長(zhǎng)度和參數(shù)中長(zhǎng)度最短的對(duì)象相同。利用*號(hào)操作符妥泉,可以將list unzip(解壓)。
- 比如:a = [1,2,3]
b = [4,5,6]
c = [4,5,6,7,8]
zipped = zip(a,b)
[(1, 4), (2, 5), (3, 6)]
zip(a,c)
[(1, 4), (2, 5), (3, 6)]
zip(*zipped)
[(1, 2, 3), (4, 5, 6)]
- 字典的內(nèi)建函數(shù):
- clear(),get(),items(),iteritems() :Returns an iterator on all items(key/valuepairs)
D.setdefault(k,x):Returns D[k] if k is a key in D; otherwise sets D[k] equal to x and returns x
values(),fromkeys(),keys(),popitem(),update()
- 集合:
- 可變:set,不可變:foneset()
12 .SciPy:
- ndarry(N維數(shù)組)吧慢,Series(變長(zhǎng)字典)涛漂,DataFrame(數(shù)據(jù)框)
- sum(axis=0或者1或者不寫),shape(),reshape(),sin(),where(),fromfunction(函數(shù)名检诗,元祖)
- 日期轉(zhuǎn)換:
- from datetime import date
from datetime import datetime
day=date.fromordinal(735190)
y=datetime.strftime(day,'%Y-%m-%d')
- 時(shí)間序列:
dates=pandas.date_range('20141001',periods=7)
dates=[2014-10-01,2014-10-02,.....,2014-10-07]
15.分組:
- tempdef.groupby('month').sum().volume- 統(tǒng)計(jì)總成交量
16.數(shù)據(jù)存取
- DataFrame df匈仗,df.to_csv(文件名)#存成csv,p.read_csv(文件名)逢慌,df.to_excel(文件名.xls,sheet_name="")