笔记
一只Monet
这个作者很懒,什么都没留下…
展开
-
numpy函数 存
https://m.runoob.com/numpy/numpy-mathematical-functions.html原创 2021-08-18 14:00:43 · 89 阅读 · 0 评论 -
正则表达式
https://gitee.com/maishucode/python/tree/master/Python%E8%BF%9B%E9%98%B6/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F原创 2021-08-17 11:46:48 · 95 阅读 · 0 评论 -
pandas 合并方法
https://github.com/yeayee/joyful-pandas/blob/master/第5章%20合并.ipynb增加行或列appendassign表的填充combine,combine_firstupdate拼接concatmergehttps://blog.csdn.net/weixin_42199542/article/details/115844539join原创 2021-08-16 17:37:17 · 81 阅读 · 0 评论 -
透视表
https://github.com/yeayee/joyful-pandas/blob/master/第4章%20变形.ipynbpivotpivot_table(功能更多,因此速度慢一些)%timeit计时aggfuncmargins汇总边际状态crosstabmelt(pivot的逆过程)https://blog.csdn.net/weixin_42199542/article/details/107774774压缩哑变量factorize...原创 2021-08-16 15:55:19 · 79 阅读 · 0 评论 -
OrderDict模块的使用
https://blog.csdn.net/brucewong0516/article/details/83992642有顺序的字典原创 2021-08-16 14:21:43 · 332 阅读 · 0 评论 -
apply 函数
可能在所有的分组函数中,apply是应用最为广泛的,这得益于它的灵活性:¶对于传入值而言,从下面的打印内容可以看到是以分组的表传入apply中:对于传入值而言,从下面的打印内容可以看到是以分组的表传入apply中df.groupby('School').apply(lambda x:print(x.head(1))) School Class Gender Address Height Weight Math PhysicsID原创 2021-08-16 14:15:14 · 1070 阅读 · 0 评论 -
过滤和变换
过滤grouped_single[['Math','Physics']].filter(lambda x:(x['Math']>32).all()).head()变换(a)传入对象transform函数中传入对象是组内的列,并且返回值需要与列长完全一致grouped_single[['Math','Height']].transform(lambda x:x-x.min()).head()如果返回了标量值,那么组内的所有元素会被广播为这个值grouped_single[['Math'原创 2021-08-16 14:00:39 · 79 阅读 · 0 评论 -
python函数与函数装饰器
https://www.cnblogs.com/eilinge/p/9705516.html关于wrapper函数装饰器https://www.runoob.com/w3cnote/python-func-decorators.html关于python函数装饰器和函数原创 2021-08-16 10:56:04 · 59 阅读 · 0 评论 -
agg
1.利用NamedAgg函数进行多个聚合注意:不支持lambda函数,但是可以使用外置的def函数In [27]:def R1(x): return x.max()-x.min()def R2(x): return x.max()-x.median()grouped_single['Math'].agg(min_score1=pd.NamedAgg(column='col1', aggfunc=R1), max_score1=p原创 2021-08-16 10:54:53 · 231 阅读 · 0 评论 -
Agg
https://github.com/yeayee/joyful-pandas/blob/master/第3章%20分组.ipynb聚合(Aggregation)聚合(Aggregation)(a)常用聚合函数所谓聚合就是把一个数列,变成一个标量,因此mean/sum/size/count/std/var/sem/describe/first/last/nth/min/max都是聚合函数group_m = grouped_single['Math']group_m.std().values/np.原创 2021-08-15 22:18:54 · 273 阅读 · 0 评论 -
pandas 分组groupby
https://github.com/yeayee/joyful-pandas/blob/master/第3章%20分组.ipynb1.根据某一列分组经过groupby后会生成一个groupby对象,该对象本身不会返回任何东西,只有当相应的方法被调用才会起作用¶grouped_single = df.groupby('School')grouped_single.get_group('S_1')2.根据某几列分组grouped_mul = df.groupby(['School','Class原创 2021-08-15 21:55:42 · 198 阅读 · 0 评论 -
pandas抽样函数sample
(a)n为样本量从df中随机抽取n行df.sample(n=5)(b)frac为抽样比df.sample(frac=0.05)按照这个比例抽取(c)replace为是否放回df.sample(n=35,replace=True).index.is_unique注意这里的.is_unique(d)axis为抽样维度,默认为0,即抽行(e)weights为样本权重,自动归一化df.sample(n=3,weights=np.random.rand(df.shape[0])).head原创 2021-08-15 16:56:35 · 1584 阅读 · 0 评论 -
pan重复元素处理pandas
1.duplicated该方法返回了是否重复的布尔列表df.duplicated('Class').head()可选参数keep默认为first,即首次出现设为不重复(默认参数),若为last,则最后一次设为不重复,若为False,则所有重复项为True2.drop_duplicates方法从名字上看出为剔除重复项,例如需要保留每组的第一个值,参数与duplicate函数类似,在传入多列时等价于将多列共同视作一个多级索引,比较重复项(如果两列的元素都相同则丢弃这一行)。...原创 2021-08-15 16:42:22 · 135 阅读 · 0 评论 -
pandas索引函数
1.wheredf.where(df['Gender']=='M')#不满足条件的行全部被设置为NaN通过这种方法筛选结果和[]操作符的结果完全一致:df.where(df['Gender']=='M').dropna()#.dropna()丢掉含nan的行第一个参数为布尔条件,第二个参数为填充值:df.where(df['Gender']=='M',np.random.rand(df.shape[0],df.shape[1])).head()#np.random.rand可以返回指定大原创 2021-08-15 16:25:16 · 111 阅读 · 0 评论 -
set_index和reset_index
1.set_index利用append参数可以将当前索引维持不变当使用与表长相同的列作为索引(需要先转化为Series,否则报错)df.shape[0]可以直接添加多级索引np.ones2.reset_index默认状态直接恢复到自然数索引:df.reset_index()用level参数指定哪一层被reset,用col_level参数指定set到哪一层https://www.cnblogs.com/cgmcoding/p/13691142.htmlhttps://www.cnblogs原创 2021-08-15 14:53:39 · 207 阅读 · 0 评论 -
pandas索引有关操作2
https://github.com/yeayee/joyful-pandas/blob/master/第2章%20索引.ipynbreindex_like的作用为生成一个横纵索引完全与参数列表一致的DataFrame,数据使用被调用的表原创 2021-08-15 10:50:36 · 52 阅读 · 0 评论 -
dataframe索引设定reindex
index_col参数reindex:索引对齐,重新排序pandas中的reindex方法可以为series和dataframe添加或者删除索引,如果新添加的索引没有对应的值,则默认为nan。如果减少索引,就相当于一个切片操作。df.reindex(index=[1101,1203,1206,2402])df.reindex(columns=['Height','Gender','Average'])#提取这几列并且索引重新排序可以在reindex中补充缺失值,fill_value和met.原创 2021-08-12 22:50:17 · 3405 阅读 · 0 评论 -
多层索引切片
在这里插入#df_using_mul.loc['C_2','street_5']#当索引不排序时,单个索引会报出性能警告#df_using_mul.index.is_lexsorted()#该函数检查是否排序df_using_mul.sort_index().loc['C_2','street_5']#df_using_mul.sort_index().index.is_lexsorted()代码片#df_using_mul.loc[('C_2','street_5'):] 报错#当不排序时原创 2021-08-12 21:33:47 · 451 阅读 · 0 评论 -
day5
多级索引直接创立tuples = [('A','a'),('A','b'),('B','a'),('B','b')]mul_index = pd.MultiIndex.from_tuples(tuples, names=('Upper', 'Lower'))pd.DataFrame({'Score':['perfect','good','fair','bad']},index=mul_index)利用zipL1 = list('AABB')L2 = list('abab')tupl原创 2021-08-12 17:21:47 · 52 阅读 · 0 评论 -
小灰pandas学习day4
布尔索引:常说的根据某行某列的元素判断是否保留该列或行,布尔符号:’&’,’|’,’~’:分别代表和and,或or,取反notdf[(df['Gender']=='F')&(df['Address']=='street_2')]df[(df['Math']>85)|(df['Address']=='street_7')]df[~((df['Math']>75)|(df['Address']=='street_1'))]#loc和[]中相应位置都能使用布尔列表选择:原创 2021-08-12 16:22:28 · 66 阅读 · 0 评论 -
小灰学pandas day4
https://github.com/yeayee/joyful-pandas/blob/master/第2章%20索引.ipynbloc索引方式:单行索引,多行索引,单列索引,多列索引,联合索引,函数式索引,布尔索引(保留含某些元素的行)df.loc[lambda x:x['Gender']=='M'].head()#loc中使用的函数,传入参数就是前面的dfdf.loc[[True if i[-1]=='4' or i[-1]=='7' else False for i in df['Ad原创 2021-08-12 15:24:41 · 40 阅读 · 0 评论 -
小白pandas学习day4
loc可以用函数式索引例:df.loc[lambda x:x[‘Gender’]==‘M’].head()#loc中使用的函数,传入参数就是前面的df原创 2021-08-12 15:00:12 · 50 阅读 · 0 评论 -
pandas小白学习day3
索引对齐特性!!在用dataframe的列计算时,一定要注意,犯过多次错误了列的删除:drop del pop原创 2021-08-12 09:56:47 · 48 阅读 · 0 评论 -
pandas小白学习day2
https://github.com/yeayee/joyful-pandas/blob/master/第1章%20Pandas基础.ipynbseries: values,index,name,dtype运用.iloc或者.loc或者df[‘列名’]即可将dataframe里的某列转换成series, .value提取值转换成array修改行或者列名(索引值)df.values每一行构成一个list作为大list里的一个值df.mean数字列每列的均值,df.max,df.min,df.sum.原创 2021-08-12 09:08:37 · 50 阅读 · 0 评论 -
2021-03-11
python debug小技巧学习笔记1.@pysnooper.snoop()```pythonimport pysnooper@pysnooper.snoop()加在函数前面,运行后可以看到输入输出变量,便于纠错。2.@pysnooper.snoop()原创 2021-08-11 17:38:21 · 46 阅读 · 0 评论 -
pandas官方文档学习day1
创建字典的方式构造dataframe遇到os模块,包括删除路径,删除指定路径文件,改变路径,查询文件大小等https://blog.51cto.com/u_12306609/2123210pd.read_csv:https://www.cnblogs.com/traditional/p/12514914.html指定列的类型、对列的数据进行变换、清洗列值为true和false、过滤行(从头/从尾)、读取行数、兼容类型、配置哪些值需要处理成 NaN、过滤空行、指定时间类型、分块读入、可以读压缩文件.原创 2021-08-11 17:50:46 · 59 阅读 · 0 评论