随笔分类 -  python

np.tile语法
摘要:>>> v = np.array([1, 0, 1])>>> vv = np.tile(v,(4,1))>>> print vv[[1 0 1] [1 0 1] [1 0 1] [1 0 1]]>>> 阅读全文

posted @ 2017-11-21 20:54 TMatrix52 阅读(159) 评论(0) 推荐(0) 编辑

mac下python安装MySQLdb模块
摘要:参考:http://blog.csdn.net/yelyyely/article/details/41114449 1、调整到anaconda下的python 2、安装有关程序 阅读全文

posted @ 2017-11-15 18:54 TMatrix52 阅读(119) 评论(0) 推荐(0) 编辑

virtualenv搭建python3 环境
摘要:参考 1、安装python3 2、创建虚拟环境: 阅读全文

posted @ 2017-11-12 18:23 TMatrix52 阅读(121) 评论(0) 推荐(0) 编辑

pandas Dataframe 构造
摘要: 阅读全文

posted @ 2017-11-01 15:00 TMatrix52 阅读(134) 评论(0) 推荐(0) 编辑

pandas apply()函数参数 args
摘要:#!/usr/bin/python import pandas as pd data = {'year':[2000,2001,2002,2001,2002],'value':[1.5,1.7,3.6,2.4,2.9]} frame = pd.DataFrame(data) def testfunc(x, str): #第一个参数代表该函数处理的每一个元素,第二个参数args是传入的参数... 阅读全文

posted @ 2017-11-01 14:24 TMatrix52 阅读(8425) 评论(0) 推荐(0) 编辑

Excel导入CSV文件中文乱码
摘要:参考: iconv -f UTF8 -t GB18030 a.csv >b.csv 或iconv -f UTF-8 -t GB18030 a.csv >b.csv 阅读全文

posted @ 2017-10-31 13:32 TMatrix52 阅读(169) 评论(0) 推荐(0) 编辑

解决Python2.7的UnicodeEncodeError: ‘ascii’ codec can’t encode异常错误
摘要:更改 sys.defaultencoding 为文件的编码方式 #! /usr/bin/env python # -*- coding: utf-8 -*- import sys reload(sys) # Python2.5 初始化后删除了 sys.setdefaultencoding 方法,我们 阅读全文

posted @ 2017-10-31 10:40 TMatrix52 阅读(123) 评论(0) 推荐(0) 编辑

python 深拷贝与浅拷贝
摘要:浅拷贝:直接赋值,传递对象的引用而已 深拷贝:包含对象里面的自对象的拷贝,所以原始对象的改变不会造成深拷贝里任何子元素的改变 不多说,之间看结果。 阅读全文

posted @ 2017-10-30 19:51 TMatrix52 阅读(125) 评论(0) 推荐(0) 编辑

Mac os fatal error: 'numpy/arrayobject.h' file not found
摘要:添加NumPy headers 给 CFLAGS: export CFLAGS="-I /usr/local/lib/python2.7/site-packages/numpy/core/include $CFLAGS"再次执行,done! 阅读全文

posted @ 2017-10-27 15:02 TMatrix52 阅读(1151) 评论(0) 推荐(0) 编辑

Cython 使用
摘要:链接: Cython是一个快速生成Python扩展模块的工具,从语法层面上来讲是Python语法和C语言语法的混血,当Python性能遇到瓶颈时,Cython直接将C的原生速度植入Python程序,这样使Python程序无需使用C重写,能快速整合原有的Python程序,这样使得开发效率和执行效率都有 阅读全文

posted @ 2017-10-26 19:31 TMatrix52 阅读(123) 评论(0) 推荐(0) 编辑

pandas.read_csv 参数 index_col=0
摘要:index_col : int or sequence or False, default None 用作行索引的列编号或者列名,如果给定一个序列则有多个行索引。 如果文件不规则,行尾有分隔符,则可以设定index_col=False 来使得pandas不使用第一列作为行索引。 如: train_d 阅读全文

posted @ 2017-10-23 17:02 TMatrix52 阅读(3065) 评论(0) 推荐(0) 编辑

os.path.join 用法
摘要:level1_list = [os.path.join(base_path, f) for f in listdir(base_path) if os.path.isdir(os.path.join(base_path, f))] 结合路径: 原来的目录层级:c:/a/b/c/test.py pri 阅读全文

posted @ 2017-10-17 19:53 TMatrix52 阅读(7271) 评论(0) 推荐(1) 编辑

UnicodeDammit
摘要:UnicodeDammit 是BS内置库, 主要用来猜测文档编码. 编码自动检测 功能可以在Beautiful Soup以外使用,检测某段未知编码时,可以使用这个方法: from bs4 import UnicodeDammit dammit = UnicodeDammit("Sacr\xc3\xa 阅读全文

posted @ 2017-10-10 11:21 TMatrix52 阅读(800) 评论(0) 推荐(0) 编辑

ASCII编码和Unicode编码的区别
摘要:链接: 计算机只能处理数字,如果要处理文本,就必须先把文本转换为数字才能处理。Unicode把所有语言都统一到一套编码里,这样就不会再有乱码问题了。Unicode标准也在不断发展,但最常用的是用两个字节表示一个字符(如果要用到非常偏僻的字符,就需要4个字节)。现代操作系统和大多数编程语言都直接支持U 阅读全文

posted @ 2017-10-10 10:56 TMatrix52 阅读(561) 评论(0) 推荐(0) 编辑

virtualenv 设置虚拟环境来运行不同版本的python
摘要:转自: http://pythonguidecn.readthedocs.io/zh/latest/dev/virtualenvs.html virtualenv 是一个创建隔绝的Python环境的 工具。virtualenv创建一个包含所有必要的可执行文件的文件夹,用来使用Python工程所需的包。 它可以独立使用,代替Pipenv。 通过pip安装virtualenv: $ pi... 阅读全文

posted @ 2017-09-07 21:25 TMatrix52 阅读(428) 评论(0) 推荐(0) 编辑

python编码问题 decode与encode
摘要:输出: 阅读全文

posted @ 2017-09-05 16:21 TMatrix52 阅读(261) 评论(0) 推荐(0) 编辑

python 正则表达式 提取网页中标签的中文
摘要:转载请注明出处 http://www.cnblogs.com/pengwang52/。 阅读全文

posted @ 2017-09-03 20:12 TMatrix52 阅读(394) 评论(0) 推荐(0) 编辑

selenium 定位无标签的元素
摘要:转载需注明出处。如: ::before 伪元素xpath css_selector、 id、 class_name各种定位失效,可以选择用, .get_attribute('innerHTML')方法,拿到源码,再进行正则匹配。 ::before "857" ... 阅读全文

posted @ 2017-09-01 14:05 TMatrix52 阅读(395) 评论(0) 推荐(0) 编辑

re.compile
摘要:详情见>>> import re >>> s = "adfad asdfasdf asdfas asdfawef asd adsfas " >>> reObj1 = re.compile('((\w+)\s+\w+)') >>> reObj1.findall(s) [('adfad asdfasdf', 'adfad'), ('asdfas asdfawef', 'asdfas'), ('as... 阅读全文

posted @ 2017-08-25 13:06 TMatrix52 阅读(149) 评论(0) 推荐(0) 编辑

Python urllib.quote
摘要:转:编码:urllib.quote(string[, safe]),除了三个符号“_.-”外,将所有符号编码,后面的参数safe是不编码的字符, 使用的时候如果不设置的话,会将斜杠,冒号,等号,问号都给编码了。 如下: >>> import urllib >>> print urllib.quote("http://neeao.com/index.php?id=1") http%3A//n... 阅读全文

posted @ 2017-08-23 19:41 TMatrix52 阅读(592) 评论(0) 推荐(0) 编辑

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示