整理一些内置函数,平时用得比较少,但是时不时遇上,记录一下吧(嘻嘻(●'◡'●))

1.help()

查看模块or函数的帮助文档

help(pandas)  #模块
Help on package pandas:

NAME
pandas DESCRIPTION
pandas - a powerful data analysis and manipulation library for Python
===================================================================== **pandas** is a Python package providing fast, flexible, and expressive data
structures designed to make working with "relational" or "labeled" data both
easy and intuitive. It aims to be the fundamental high-level building block for
doing practical, **real world** data analysis in Python. Additionally, it has
the broader goal of becoming **the most powerful and flexible open source data
analysis / manipulation tool available in any language**. It is already well on
its way toward this goal. Main Features
-------------
Here are just a few of the things that pandas does well: - Easy handling of missing data in floating point as well as non-floating
point data
- Size mutability: columns can be inserted and deleted from DataFrame and
higher dimensional objects
- Automatic and explicit data alignment: objects can be explicitly aligned
to a set of labels, or the user can simply ignore the labels and let
`Series`, `DataFrame`, etc. automatically align the data for you in
computations
- Powerful, flexible group by functionality to perform split-apply-combine
operations on data sets, for both aggregating and transforming data
- Make it easy to convert ragged, differently-indexed data in other Python
and NumPy data structures into DataFrame objects
- Intelligent label-based slicing, fancy indexing, and subsetting of large
data sets
- Intuitive merging and joining data sets
- Flexible reshaping and pivoting of data sets
- Hierarchical labeling of axes (possible to have multiple labels per tick)
- Robust IO tools for loading data from flat files (CSV and delimited),
Excel files, databases, and saving/loading data from the ultrafast HDF5
format
- Time series-specific functionality: date range generation and frequency
conversion, moving window statistics, moving window linear regressions,
date shifting and lagging, etc. PACKAGE CONTENTS
_libs (package)
_version
api (package)
compat (package)
computation (package)
conftest
core (package)
errors (package)
formats (package)
io (package)
json
lib
parser
plotting (package)
stats (package)
testing
tests (package)
tools (package)
tseries (package)
tslib
types (package)
util (package) SUBMODULES
_hashtable
_lib
_tslib
offsets DATA
IndexSlice = <pandas.core.indexing._IndexSlice object>
NaT = NaT
__docformat__ = 'restructuredtext'
datetools = <module 'pandas.core.datetools' from 'F:\\Anaconda\\lib\\s...
describe_option = <pandas.core.config.CallableDynamicDoc object>
get_option = <pandas.core.config.CallableDynamicDoc object>
options = <pandas.core.config.DictWrapper object>
plot_params = {'xaxis.compat': False}
reset_option = <pandas.core.config.CallableDynamicDoc object>
set_option = <pandas.core.config.CallableDynamicDoc object> VERSION
0.20.3 FILE
f:\anaconda\lib\site-packages\pandas\__init__.py
help(list)  #函数
Help on class list in module builtins:

class list(object)
| list() -> new empty list
| list(iterable) -> new list initialized from iterable's items
|
| Methods defined here:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return key in self.
|
| __delitem__(self, key, /)
| Delete self[key].
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(...)
| x.__getitem__(y) <==> x[y]
|
| __gt__(self, value, /)
| Return self>value.
|
| __iadd__(self, value, /)
| Implement self+=value.
|
| __imul__(self, value, /)
| Implement self*=value.
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.n
|
| __ne__(self, value, /)
| Return self!=value.
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| __reversed__(...)
| L.__reversed__() -- return a reverse iterator over the list
|
| __rmul__(self, value, /)
| Return self*value.
|
| __setitem__(self, key, value, /)
| Set self[key] to value.
|
| __sizeof__(...)
| L.__sizeof__() -- size of L in memory, in bytes
|
| append(...)
| L.append(object) -> None -- append object to end
|
| clear(...)
| L.clear() -> None -- remove all items from L
|
| copy(...)
| L.copy() -> list -- a shallow copy of L
|
| count(...)
| L.count(value) -> integer -- return number of occurrences of value
|
| extend(...)
| L.extend(iterable) -> None -- extend list by appending elements from the iterable
|
| index(...)
| L.index(value, [start, [stop]]) -> integer -- return first index of value.
| Raises ValueError if the value is not present.
|
| insert(...)
| L.insert(index, object) -- insert object before index
|
| pop(...)
| L.pop([index]) -> item -- remove and return item at index (default last).
| Raises IndexError if list is empty or index is out of range.
|
| remove(...)
| L.remove(value) -> None -- remove first occurrence of value.
| Raises ValueError if the value is not present.
|
| reverse(...)
| L.reverse() -- reverse *IN PLACE*
|
| sort(...)
| L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE*
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __hash__ = None

2.hex()

将十进制转成十六进制(括号里放十进制的数),返回一个字符串

hex(10)
'0xa'
hex(99)
'0x63'
type(hex(99))
str

3.oct()

将十进制转成八进制,返回一个字符串

oct(1307)
'0o2433'
oct(2013)
'0o3735'
type(oct(2013))
str

4.bin()

将十进制转成二进制,返回一个字符串

bin(6)
'0b110'
type(bin(6))
str

5.id()

获取对象的内存地址

a = "小可爱"
id(a)
496383449200
b = 20160101
id(b)
496382826736

6.dir()

dir() 函数不带参数时,返回当前范围内的变量、方法和定义的类型列表;

带参数时,返回参数的属性、方法列表。

如果参数包含方法__dir__(),该方法将被调用。

如果参数不包含__dir__(),该方法将最大限度地收集参数信息

dir()
['In',
'Out',
'_',
'_1',
'_10',
'_11',
'_12',
'_14',
'_15',
'_16',
'_17',
'_18',
'_19',
'_2',
'_20',
'_22',
'_23',
'_24',
'_25',
'_26',
'_27',
'_28',
'_29',
'_3',
'_30',
'_31',
'_33',
'_35',
'_38',
'_39',
'_4',
'_40',
'_41',
'_42',
'_43',
'_44',
'_45',
'_5',
'_6',
'__',
'___',
'__builtin__',
'__builtins__',
'__doc__',
'__loader__',
'__name__',
'__package__',
'__spec__',
'_dh',
'_i',
'_i1',
'_i10',
'_i11',
'_i12',
'_i13',
'_i14',
'_i15',
'_i16',
'_i17',
'_i18',
'_i19',
'_i2',
'_i20',
'_i21',
'_i22',
'_i23',
'_i24',
'_i25',
'_i26',
'_i27',
'_i28',
'_i29',
'_i3',
'_i30',
'_i31',
'_i32',
'_i33',
'_i34',
'_i35',
'_i36',
'_i37',
'_i38',
'_i39',
'_i4',
'_i40',
'_i41',
'_i42',
'_i43',
'_i44',
'_i45',
'_i46',
'_i5',
'_i6',
'_i7',
'_i8',
'_i9',
'_ih',
'_ii',
'_iii',
'_oh',
'a',
'b',
'exit',
'get_ipython',
'numpy',
'pandas',
'quit',
'result',
'sys',
'x']
dir(list)
['__add__',
'__class__',
'__contains__',
'__delattr__',
'__delitem__',
'__dir__',
'__doc__',
'__eq__',
'__format__',
'__ge__',
'__getattribute__',
'__getitem__',
'__gt__',
'__hash__',
'__iadd__',
'__imul__',
'__init__',
'__init_subclass__',
'__iter__',
'__le__',
'__len__',
'__lt__',
'__mul__',
'__ne__',
'__new__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__reversed__',
'__rmul__',
'__setattr__',
'__setitem__',
'__sizeof__',
'__str__',
'__subclasshook__',
'append',
'clear',
'copy',
'count',
'extend',
'index',
'insert',
'pop',
'remove',
'reverse',
'sort']

7.all()

判断列表或元组中的所有元素是否都为True,如果都为True,那么就返回True。

0,空值(即""),None,False均被判定为False,其余为True。

Remember that,空列表、空元组返回的是True,不是False哦

all([1, 2, 3, 4])
True
all([0, 1, 2, 3])
False
all(["", 1, 2, 3])
False
all([None, 1])
False
all([])
True
all(())
True

8.any()

判断列表或元组中的元素,如果有一个为True,那么就返回True。

any([0, None, 1])
True
any(["", False])
False

all跟any的区别就是:all要全部True才返回True,any只要有一个True就返回True。

9.abs()

返回数字的绝对值

abs(-100)
100
abs(20170516)
20170516

10.map(function, iterable, …)

根据函数对序列做映射(看例子好懂一点)

def result(x):
return x + 100
map(result, [1,2,3,4,5])
<map at 0x7392c4a390>

11.range(start, stop, step)

返回一个对象,instead of 一个列表(python2 返回的才是列表),用list(range())可实现输出为列表。

range(10)
range(0, 10)
list(range(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
type(range(10))
range

12.chr()

返回整数(十进制or十六进制)对应的ASCII字符。

chr(2017)
'ߡ'
chr(0x666)
'٦'

13.max()

返回给定参数的最大值,参数可以为序列

max([1,2,3,4,2017])
2017
max(1,2,2333)
2333

14.min()

返回给定参数的最大值,参数可以为序列

min("a", "b", "c")
'a'
min(1307, 1401, 1206)
1206

15.len()

返回对象(字符、列表、元组等)长度或项目个数

len(("a", "b", "c"))
3
len("I love you Math!")
16

16.reversed()

返回一个反转的迭代器, 要转换的序列可以是 tuple, string, list 或 range

a = ("Mike", "love", "Cathy")
print(list(reversed(a)))
['Cathy', 'love', 'Mike']
b = [520, 1314, 5201314]
print(list(reversed(b)))
[5201314, 1314, 520]

17.sorted()

对可迭代对象进行排序操作,默认是升序(参数reverse= False)

sorted([1, 2, 999])
[1, 2, 999]
sorted([1, 2, 999], reverse=True)
[999, 2, 1]

18.isinstance()

判断一个对象是否是一个已知的类型,类似 type()

isinstance([1], list)
True
isinstance([1], dict)
False

19.type()

返回对象的类型

type(20160101)
int
type(20160101) == int
True

isinstance() 与 type() 区别:

type() 不会认为子类是一种父类类型,不考虑继承关系。

isinstance() 会认为子类是一种父类类型,考虑继承关系。

如果要判断两个类型是否相同推荐使用 isinstance()。

20.divmod()

求商、求余

divmod(8, 2)
(4, 0)
divmod(8.0, 2)
(4.0, 0.0)
divmod(-8, 2.0)
(-4.0, 0.0)

21.hash()

获取取一个对象(字符串或者数值等)的哈希值

hash('Love you')
5600379523179052084
hash(8888)
8888
hash('8888')
-5690624612815825000

记录一些python内置函数的更多相关文章

  1. python内置函数print输出到文件,实现日志记录的功能

    # bulid time 2018-6-22 import os import time def log(*args, **kwargs): # *kargs 为了通用 可不传 rule = &quo ...

  2. 【转】Python 内置函数 locals() 和globals()

    Python 内置函数 locals() 和globals() 转自: https://blog.csdn.net/sxingming/article/details/52061630 1>这两 ...

  3. Python | 内置函数(BIF)

    Python内置函数 | V3.9.1 | 共计155个 还没学完, 还没记录完, 不知道自己能不能坚持记录下去 1.ArithmeticError 2.AssertionError 3.Attrib ...

  4. python内置函数

    python内置函数 官方文档:点击 在这里我只列举一些常见的内置函数用法 1.abs()[求数字的绝对值] >>> abs(-13) 13 2.all() 判断所有集合元素都为真的 ...

  5. python 内置函数和函数装饰器

    python内置函数 1.数学相关 abs(x) 取x绝对值 divmode(x,y) 取x除以y的商和余数,常用做分页,返回商和余数组成一个元组 pow(x,y[,z]) 取x的y次方 ,等同于x ...

  6. Python基础篇【第2篇】: Python内置函数(一)

    Python内置函数 lambda lambda表达式相当于函数体为单个return语句的普通函数的匿名函数.请注意,lambda语法并没有使用return关键字.开发者可以在任何可以使用函数引用的位 ...

  7. [python基础知识]python内置函数map/reduce/filter

    python内置函数map/reduce/filter 这三个函数用的顺手了,很cool. filter()函数:filter函数相当于过滤,调用一个bool_func(只返回bool类型数据的方法) ...

  8. Python内置函数进制转换的用法

    使用Python内置函数:bin().oct().int().hex()可实现进制转换. 先看Python官方文档中对这几个内置函数的描述: bin(x)Convert an integer numb ...

  9. Python内置函数(12)——str

    英文文档: class str(object='') class str(object=b'', encoding='utf-8', errors='strict') Return a string  ...

随机推荐

  1. 【c# 学习笔记】面向对象编程的应用

    在平时的开发过程中,面向对象编程的应用肯定必不可少.但前面的内容只是单独介绍了类.面向对象思想和接口,那么我们怎么在平时工作中来应用他们来实现面向对象编程呢? 如果你想设计一个Dog类,有了类的概念后 ...

  2. Ubuntu构建LVS+Keepalived高可用负载均衡集群【生产环境部署】

    1.环境说明: 系统版本:Ubuntu 14.04 LVS1物理IP:14.17.64.2   初始接管VIP:14.17.64.13 LVS2物理IP:14.17.64.3   初始接管VIP:14 ...

  3. 【OpenGL学习】 四种绘制直线的算法

    我是用MFC框架进行测试的,由于本人也没有专门系统学习MFC框架,代码若有不足之处,请指出. 一,先来一个最简单的DDA算法 DDA算法全称为数值微分法,基于微分方程来绘制直线. ①推导微分方程如下: ...

  4. 解决X-Scan安装后“无法启动此程序,因为计算机丢失NPPTools.dll”

    最近在一本书中看到X-Scan这个扫描器,虽说X-Scan相比现在的扫描器已经有点过时了,但也想下载来试一试,谁知道在VM中Win7安装时出现这种问题 可以在脚本之家找到缺失的这个文件:https:/ ...

  5. php csv 简单的导入

    if($act == 'user_upload_do'){ global $db; $filename = $_FILES['file']['tmp_name']; if (empty ($filen ...

  6. 2019春《C语言程序设计》课程设计的安排

    课程设计的安排 课前准备: 要求同学们注册码云,并登陆: 要求组长加入由老师创建的一级组织:"2019春C语言": 要求组长建立二级组织,给自己的小组取个好听的名字,并邀请本组成员 ...

  7. LeNet-5 pytorch+torchvision+visdom

    # ====================LeNet-5_main.py=============== # pytorch+torchvision+visdom # -*- coding: utf- ...

  8. JS 03事件

    <script type="text/javascript"> function getUserInput() { //获取用户输入的内容 var val = docu ...

  9. Board Game CodeForces - 605D (BFS)

    大意: 给定$n$张卡$(a_i,b_i,c_i,d_i)$, 初始坐标$(0,0)$. 假设当前在$(x,y)$, 若$x\ge a_i,y\ge b_i$, 则可以使用第$i$张卡, 使用后达到坐 ...

  10. Apache2.4+Tomcat7.0+php5.5整合配置详解

    在上一篇的基础上,继续添加php的配置 一.首先下载php5.5 首先下载php5.5,到官网下载http://www.php.net/downloads.php,参考http://www.cnblo ...