大数据分析第三节课-python_第1页
大数据分析第三节课-python_第2页
大数据分析第三节课-python_第3页
大数据分析第三节课-python_第4页
大数据分析第三节课-python_第5页
已阅读5页,还剩32页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、第三节课-PYTHON常用的数据结构字典列表元祖SeriesDataFrame官网 IO:导入导出数据pd.read_csv(filepath_or_buffer, sep=, header=infer, index_col=None, names=None, na_values=None, error_bad_lines=True, parse_dates=False)注意:我们只推荐只有read_csvEXCEL过于繁琐,甚至会出现错误EXCEL转换成CSV或者TXT格式I/O数据写出DataFrame.to_csv(path_or_buf=None, sep=, , na_rep=, f

2、loat_format=None, columns=None, header=True, index=True, index_label=None, mode=w, encoding=None, compression=None, quoting=None, quotechar=, line_terminator=n, chunksize=None, tupleize_cols=False, date_format=None, doublequote=True, escapechar=None, decimal=., *kwds)dataframe与series的方法切片列选取rename删除

3、重复值计算频次过滤计算增加新的一列索引选取我们讲解四个最核心最常用的方法df.locdf.ilocdf.ixdf.query区别于联系loc输入的值必须是索引的名称,iloc输入的是索引的位置ix是loc与iloc的结合,输入的既可以是名称也可以是位置query是一种简便的方式,只能对column进行过滤索引的设置与逆操作set_index:给当前的数据集设置索引reset_index:将当前的索引设置成列注意几个参数appenddrop多重索引多重索引既可以作用于行,也可以作用于列level是我们选取层次索引的参数df.loc的用法与单层索引类似df.xs允许我们通过Level制定索引sli

4、ceindexslice多重索引范围选取使用slice指定选取直接使用列表多重索引使用之前必须对索引进行排序(slice)df.sort_index(level )Pandas常用函数Pandas常用函数分组计算Group By : split apply combinesplit: 很具某些条件对数据进行分组apply:对每一个group独立的应用函数combine:将结果数据组合到某种数据结构中splitgroup by columnsgroup by index遍历遍历每一个group选择某个group其它的一些group特征aggregation一次应用多个函数对不同的column应用

5、不同的函数Transformation会返回一个数据集,这个数据集与group具有同样的索引以及大小举例说明:对数据集进行标准化:zscore = lambda s : (s s.mean() / s.td()transformed = df.groupby(key).transform(zscore)Filtration返回原始数据集的一个子集举个例子:过滤group的size过滤group里某个元素指的和或者长度多表操作普及一点简单的知识join: left, right , inner, outerkeyone-to-onemany-to-onemany-to-manyConcatApp

6、end增加一个数据集增加一行增加一列Mergejoining key columnsjoining key indexesjoining key columns on indexes内置函数Enumerate(iterable,start = 0)Return an enumerate object. iterable must be a sequence, an iterator, or some other object which supports iteration. The _next_() method of the iterator returned by enumerate()

7、 returns a tuple containing a count (from start which defaults to 0) and the values obtained from iterating over iterableZip()Make an iterator that aggregates elements from each of the iterables.Returns an iterator of tuples, where the i-th tuple contains the i-th element from each of the argument s

8、equences or iterables. The iterator stops when the shortest input iterable is exhausted. With a single iterable argument, it returns an iterator of 1-tuples使用透视进行数据重组Pivote the columns are the unique variables and an index of dates identifies individual observationsStack and Unstackstack: “pivot” a

9、level of the (possibly hierarchical) column labels, returning a DataFrame with an index with a new inner-most level of row labels.unstack: inverse operation from stack: “pivot” a level of the (possibly hierarchical) row index to the column axis, producing a reshaped DataFrame with a new inner-most level of column labels.透视表pd.pivot_table交互表pd.crosstabPower py Top functions创建数组1-D2-D ,3-D.np.arrangenp.linspacenp.onesnp.eyenp.zerosnp.randomnp.emptynp.linespace基础操作属性ndimshapesizelen()方法np.wherenp.linspacenp.co

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论