Pandas基本介紹——DataFrame入門學習html
前篇文章中,小生初步介紹pandas庫中的Series結構的建立與運算,今天小生繼續「死磕本身」爲你們介紹pandas庫的另外一種最爲常見的數據結構DataFrame。數據結構
DataFrame是二維標記的數據結構(三維結構請看Panel,後面爲你們介紹),你能夠把它當作一張電子表格或者SQL關係庫中的表格。DataFrame是pandas庫中最爲常見的一種數據結構,正如Series同樣,它也有不少不一樣的建立方法:學習
一、 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