Python知识分享网 - 专业的Python学习网站 学Python,上Python222
Python之路V2.0 PDF 下载
发布于:2024-04-21 11:12:50
(假如点击没反应,多刷新两次就OK!)

Python之路V2.0 PDF 下载   图1

 

 

资料内容:

 

一、Python基础
Python基础 主要总结Python常用内置函数;Python独有的语法特性、关键词 nonlocal , global 等;
内置数据结构包括:列表(list), 字典(dict), 集合(set), 元组(tuple) 以及相关的高级模块 collections
Counter , namedtuple , defaultdict heapq 模块。目前共有 90 个小例子。
1 求绝对值
pd.pivot_table(df, index=['Manager', 'Rep'], values=['Price'], aggfunc=np.sum)
from sklearn.cluster import KMeans
KMeans( n_clusters=3 )绝对值或复数的模
 
In [1]: abs(-6)
Out[1]: 6

 

2 元素都为真
接受一个迭代器,如果迭代器的 所有元素 都为真,那么返回 True ,否则返回 False
 
In [2]: all([1,0,3,6])
Out[2]: False
In [3]: all([1,2,3])
Out[3]: True

 

3 元素至少一个为真
接受一个迭代器,如果迭代器里 至少有一个 元素为真,那么返回 True ,否则返回 False
 
In [4]: any([0,0,0,[]])
Out[4]: False
In [5]: any([0,0,1])
Out[5]: True

 

4 ascii展示对象
调用对象的repr() 方法,获得该方法的返回值,如下例子返回值为字符串
 
In [1]: class Student():
...: def __init__(self,id,name):
...: self.id = id
...: self.name = name
...: def __repr__(self):
...: return 'id = '+self.id +', name = '+self.name
...:
...:
In [2]: xiaoming = Student(id='001',name='xiaoming')
In [3]: print(xiaoming)
id = 001, name = xiaoming
In [4]: ascii(xiaoming)
Out[4]: 'id = 001, name = xiaoming'