pandas库学习笔记(二)DataFrame入门学习

Pandas基本介绍——DataFrame入门学习html

 

前篇文章中,小生初步介绍pandas库中的Series结构的建立与运算,今天小生继续“死磕本身”为你们介绍pandas库的另外一种最为常见的数据结构DataFrame。数据结构

 

DataFrame是二维标记的数据结构(三维结构请看Panel,后面为你们介绍),你能够把它当作一张电子表格或者SQL关系库中的表格。DataFrame是pandas库中最为常见的一种数据结构,正如Series同样,它也有不少不一样的建立方法:学习

  • Dict of 1D ndarrays, lists, dicts, or Series
  • 2-D numpy.ndarray
  • Structured or record ndarray
  • A Series
  • Another DataFrame

一、  from dict of Series or dicts3d

DataFrame中的index与Series结构中的index是独立的。若是输入数据是一个嵌套的dict结构,系统首先会将内部的dict转化为Series。若是初始化时没有给列名赋值,列名将会默认问dict keys.htm

 

行标和列标均可以经过index和columns属性得到。blog

注:当一个column集合与dict数据同时初始化,此时column集合将取代dict数据中的key值成为DataFrame的列名。ip

 

二、  from dict of ndarrays/listsci

ndarrays长度必须都是同样的,若是index手动初始化,index的长度一样须要与ndarrays同样长。若是index没有手动给出,range(n-1)将默认初始化为index。get

 

 

三、  from structured or record arraypandas

这种状况与dict of arrays同样。

 

 

四、  from a list of dicts

 

五、  from a dict of tuples

能够经过tuples dictionary建立一个multi-index frame。

 

 

六、  from a Series

DataFrame的index与Series的index一致,若是没有其余column名称给出,DataFrame的column值与Series的一致。

 

 

DataFrame数据对齐运算

一、两个不一样的DataFrame进行运算时,DataFrame会根据行标和列标将对应位置的值一一对应运算。

二、DataFrame和Series进行运算时,将会根据Series的index对DataFrame的全部columns进行逐行计算。

三、针对带有时间序列的数据,DataFrame index也能够是时间序列,the broadcasting will be column-wise。

暂先总结这些,DataFrame的运算和初始化方法还有不少,这里就不加赘述,你们能够参考连接:http://pandas.pydata.org/pandas-docs/version/0.18.1/dsintro.html

相关文章
相关标签/搜索