
python
星之空殇
这个作者很懒,什么都没留下…
展开
-
Gamma压缩与解压
#!/usr/bin/python#coding:utf-8def to_bin(num): a=int(num); mid=[]; str='' while True: if a==0: break; a,rem=divmod(a,2); mid.append(rem); mid.reverse(); for i in mid: str=str+'%d'%i r原创 2015-12-01 12:00:40 · 1497 阅读 · 0 评论 -
python正则表达式(re)
re.match re.match 尝试从字符串的开始匹配一个模式,如:下面的例子匹配第一个单词。 import retext = "JGood is a handsome boy, he is cool, clever, and so on..."m = re.match(r"(\w+)\s", text)if m:print m.group(0), '转载 2016-03-01 13:19:37 · 244 阅读 · 0 评论 -
python集合操作
python的set和其他语言类似, 是一个无序不重复元素集, 基本功能包括关系测试和消除重复元素. 集合对象还支持union(联合), intersection(交), difference(差)和sysmmetric difference(对称差集)等数学运算. sets 支持 x in set, len(set),和 for x in set。作为一个无序的集合,sets不记录转载 2016-02-29 13:16:27 · 579 阅读 · 0 评论 -
python爬虫时报错
爬虫时由于中文报错UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 0: ordinal not in range(128)解决方案:在代码开头输入如下代码:import sysreload(sys)sys.setdefaultencoding('utf8')原创 2016-06-23 12:19:08 · 494 阅读 · 0 评论 -
如何使用ip代理爬虫
import urllibimport socketimport urllib2import timefrom bs4 import BeautifulSoupurl = 'http://www.xicidaili.com/nn/'target="https://msdn.microsoft.com"dirt={}proxy = {'http': '223.15.151.149原创 2017-03-08 14:55:19 · 1339 阅读 · 0 评论 -
python各种库安装
Python安装中默认会安装pip工具,要安装各种库,只需要进入www.lfd.uci.edu/~gohlke/pythonlibs网站,下载对应的库文件;例如我需要安装scipy库:进入网站,找到需要安装的scipy,下载对应Python版本的.whl文件。在终端执行命令:python -m pip install -U scipy-0.19.0-cp27-cp27m-win_amd原创 2017-03-31 20:03:47 · 494 阅读 · 0 评论 -
python数据分析(统计学和线性代数)
1、求矩阵的逆代码#coding:utf8import numpy as npA=np.mat("2 3 4; 4 2 6;10 -4 18")print "A\n",Ainverse=np.linalg.inv(A) #求矩阵的逆print "inverse of A\n",inverseprint "Check\n",A*inverse #检验相乘是否为单位矩阵pr原创 2017-11-19 14:58:49 · 1471 阅读 · 0 评论 -
python数据分析(pandas入门)
1、pandas数据结构之DataFrameDataFrame生成方式:1、从另一个DataFrame创建。2、从具有二维形状的NumPy数组或数组的复合结构生成。3、使用Series创建。4、从CSV之类文件生成。下面介绍DataFrame的简单用法:a):读取文件代码:from pandas.io.parsers import read_csvdf=read_csv(原创 2017-11-21 14:58:38 · 5818 阅读 · 1 评论 -
Python解决matplotlib画图中文显示异常问题
1、安装开源库pyplotzpip install pyplotz2、引入包from pyplotz.pyplotz import PyplotZfrom pyplotz.pyplotz import pltpltz=PyplotZ()pltz.enable_chinese()3、使用pltz代替pyplot ...原创 2018-11-05 21:10:25 · 789 阅读 · 1 评论