
Python数据分析
倾城琉璃
这个作者很懒,什么都没留下…
展开
-
python中xrange和range的异同
range 函数说明:range([start,] stop[, step]),根据start与stop指定的范围以及step设定的步长,生成一个序列。range示例: >>> range(5) [0, 1, 2, 3, 4] >>> range(1,5) [1, 2, 3, 4] >>> range(0,6,2)[0, 2, 4]xrange转载 2017-07-29 10:24:32 · 230 阅读 · 0 评论 -
Python中的join()函数的用法
Python中的join()函数的用法http://www.cnblogs.com/jsplyy/p/5634640.html函数:string.join()Python中有join()和os.path.join()两个函数,具体作用如下: join(): 连接字符串数组。将字符串、元组、列表中的元素以指定的字符(分隔符)连接生成一个新的字符串 o转载 2017-10-23 10:16:36 · 384 阅读 · 0 评论 -
# 比较filter,map,reduce
#coding:utf-8__author__ = 'kx'# 比较filter,map,reducea=lambda x:x**2listTest=[12,29,22,17,23,8]b=filter(a,listTest)print(b)#测试一个函数为空的b1=filter(None,listTest)print(b1)#测试一个列表是字符串类型的def a1(s):原创 2017-10-24 20:14:29 · 211 阅读 · 0 评论 -
requests+lxml 爬虫练习
import requestsimport lxml.htmletree=lxml.html.etreeimport codecsdef get_info_list(url): html=requests.get(url).content # print(html) sel=etree.HTML(html) title_li=sel.xpath('//...原创 2019-07-23 17:29:48 · 442 阅读 · 0 评论 -
使用 python3.6 时安装好 lxml 时按照许多网上的教程来引入会发现 etree 没被引入进来
使用 python3.6 时安装好 lxml 时按照许多网上的教程来引入会发现 etree 没被引入进来解决办法:import lxml.htmletree = lxml.html.etree这样就可以使用 etree 了,亲测有效,如果总觉得后期xpath,定位不到数据,不用怀疑是etree的问题,相信我,是你自己的问题。...原创 2019-07-28 15:08:31 · 472 阅读 · 0 评论 -
XPath里面几种定位不到数据的解决办法
1.缩短定位路径,利用属性定位,比序列定位好像好用一些;2.tbody 标签是个坑,去掉它;3.查看获取的HTML源码中有没有想要的数据,有的是获取不到的,;4.学习一下正则表达式,配合使用;...原创 2019-07-28 15:11:19 · 11904 阅读 · 3 评论 -
Python正则练习
__author__ = '***'import reprint(re.match('www','www.runoob.com'))print(re.match('www','www.runoob.com').span())print(re.match('com','www.runoob.com'))line="Cats are smarter than dogs"# #.* 表示任...原创 2019-07-28 15:07:50 · 203 阅读 · 0 评论 -
scipy中的包及其作用
scipy有多个子包组成子包名描述cluster聚类算法constants物理和数学上的一些常量fftpack快速傅立叶变化integrate集成和常微分方程的求解interpolate插值和平滑样条函数io输入和输出转载 2017-07-28 21:43:45 · 940 阅读 · 0 评论 -
python数据分析师面试题选
python数据分析部分1. 如何利用SciKit包训练一个简单的线性回归模型利用linear_model.LinearRegression()函数 # Create linear regression objectregr = linear_model.LinearRegression()# Train the model using the training set转载 2017-07-28 16:58:40 · 1331 阅读 · 0 评论 -
Sending a Letter
Great work!Now let's write a get_letter_gradefunction that takes a number score as input and returns a string with the letter grade that that student should receive.lloyd = { "name": "Lloyd原创 2017-05-12 21:48:12 · 587 阅读 · 0 评论 -
numpy的random模块
原文来自http://www.mamicode.com/info-detail-507676.html标签:【说明】翻译自官网的文档。 随机抽样 (numpy.random)简单的随机数据rand(d0, d1, ..., dn)随机值>>> np.random.rand(3,2)array([[转载 2017-05-25 10:51:42 · 335 阅读 · 0 评论 -
编码和字符串
字符编码我们已经讲过了,字符串也是一种数据类型,但是,字符串比较特殊的是还有一个编码问题。因为计算机只能处理数字,如果要处理文本,就必须先把文本转换为数字才能处理。最早的计算机在设计时采用8个比特(bit)作为一个字节(byte),所以,一个字节能表示的最大的整数就是255(二进制11111111=十进制255),如果要表示更大的整数,就必须用更多的字节。比如两个字节可以表示的最大转载 2017-05-16 14:22:23 · 284 阅读 · 0 评论 -
Python读写exce文件
本文转自python操作Excel读写--使用xlrd一、安装xlrd模块 到python官网下载http://pypi.python.org/pypi/xlrd模块安装,前提是已经安装了python 环境。二、使用介绍 1、导入模块 import xlrd 2、打开Excel文件读取数据 data = xlrd.open_workbook('excelFile.x转载 2017-05-07 19:08:19 · 373 阅读 · 0 评论 -
Python读取Excel文件遇到的编码问题(pycharm)
1.读取中文文件名,出现错误2.控制台输出中文乱码3.decode和encode4.UnicodeDecodeError: 'utf8' codec can't decode bytes in position 0-1: invalid data错误原创 2017-05-16 20:06:06 · 16478 阅读 · 0 评论 -
如何在python中倒序遍历数组
num = [5,9,10,23,89]for i in range(0, num.__len__())[::-1]: print num[i]原创 2017-05-09 15:11:30 · 16688 阅读 · 0 评论 -
Python从Excel中读取日期一列
import xlrdimport datetimefile=u"伏特加.xls"#注意读中文文件名稍微处理一下data=xlrd.open_workbook(file)table = data.sheet_by_index(0)#按照索引读Excel文件colContent=table.col_values(1)#读某一列,日期在第二列nrows=table.nrows #行数p原创 2017-05-16 20:37:04 · 5705 阅读 · 0 评论 -
读取TXT文件中的最后一个数据
import csvimport sysimport jsonreload(sys)sys.setdefaultencoding( "utf-8" )filename="AmazonRaisinResult.txt"with open (filename,"rb")as f: votes=[] #将txt文件读进来,这种评论数据不同于数值型数据 for rev原创 2017-05-10 16:51:14 · 1175 阅读 · 0 评论 -
Python静态检查工具
Python是一门动态语言。在给python传参数的时候并没 有严格的类型限制。写python程序的时候,发现错误经常只能在执行的时候发现。有一些 错误由于隐藏的比较深,只有特定逻辑才会触发,往往导致需要花很多时间才能将语法错误慢慢排查出来。其实有一些错误是很明显的,假如能在写程序的时候发现这些错误,就能提高工作效率。注:习惯了C/C++等编译语言,使用像Python这种动态语言,总有点不转载 2017-07-29 10:51:20 · 1567 阅读 · 0 评论