熱線電話:13121318867

登錄
首頁精彩閱讀Series是什么?
Series是什么?
2020-05-12
收藏
  1. Series數據結構

Series是一種類似于一位數組的對象,由一組數據及一組與之相關的數據標簽(即索引)組成。


Python數據分析之<wordsbank_match class='wbmatch' location='/map/<a href='/map/pandas/' style='color:#000;font-size:inherit;'>pandas</a>/' style='cursor:pointer;'><a href='/map/pandas/' style='color:#000;font-size:inherit;'>pandas</a></wordsbank_match>數據結構


上面這樣的數據結構就是Series,第一列數字是數據標簽,第二列是具體的數據,數據標簽與數據是一一對應的,上面的數據用Excel表展示如下表所示:


Python數據分析之<wordsbank_match class='wbmatch' location='/map/<a href='/map/pandas/' style='color:#000;font-size:inherit;'>pandas</a>/' style='cursor:pointer;'><a href='/map/pandas/' style='color:#000;font-size:inherit;'>pandas</a></wordsbank_match>數據結構


2、創建一個Series


創建一個Series利用的方法是pd.Series(),通過給Series()方法傳入不同的對象即可實現


(1)傳入一個列表


傳入一個列表的實際如下所示:


Python數據分析之<wordsbank_match class='wbmatch' location='/map/<a href='/map/pandas/' style='color:#000;font-size:inherit;'>pandas</a>/' style='cursor:pointer;'><a href='/map/pandas/' style='color:#000;font-size:inherit;'>pandas</a></wordsbank_match>數據結構


如果只是傳入一個列表不指定數據標簽,那么Series會默認使用從0開始的數做數據標簽,上面的0、1、2、3就是默認的數據標簽。


(2)指定索引


直接傳入一個列表會使用默認索引,也可以通過設置index參數來自定義索引。


Python數據分析之<wordsbank_match class='wbmatch' location='/map/<a href='/map/pandas/' style='color:#000;font-size:inherit;'>pandas</a>/' style='cursor:pointer;'><a href='/map/pandas/' style='color:#000;font-size:inherit;'>pandas</a></wordsbank_match>數據結構


(3)傳入一個字典


也可以將數據與數據標簽以key:value(字典)的形式傳入,這樣字典的key值就是數據標簽,value就是數據值。


Python數據分析之<wordsbank_match class='wbmatch' location='/map/<a href='/map/pandas/' style='color:#000;font-size:inherit;'>pandas</a>/' style='cursor:pointer;'><a href='/map/pandas/' style='color:#000;font-size:inherit;'>pandas</a></wordsbank_match>數據結構


Python數據分析之<wordsbank_match class='wbmatch' location='/map/<a href='/map/pandas/' style='color:#000;font-size:inherit;'>pandas</a>/' style='cursor:pointer;'><a href='/map/pandas/' style='color:#000;font-size:inherit;'>pandas</a></wordsbank_match>數據結構


3、利用index方法獲取Series的索引


獲取一組數據的索引是比較常見的需求,直接利用index方法 就可以獲取Series的索引值,代碼如下圖所示:


Python數據分析之<wordsbank_match class='wbmatch' location='/map/<a href='/map/pandas/' style='color:#000;font-size:inherit;'>pandas</a>/' style='cursor:pointer;'><a href='/map/pandas/' style='color:#000;font-size:inherit;'>pandas</a></wordsbank_match>數據結構


4、利用values方法獲取Series的值


與索引值相對用的就是獲取Series的值,使用的方法是values方法。


Python數據分析之<wordsbank_match class='wbmatch' location='/map/<a href='/map/pandas/' style='color:#000;font-size:inherit;'>pandas</a>/' style='cursor:pointer;'><a href='/map/pandas/' style='color:#000;font-size:inherit;'>pandas</a></wordsbank_match>數據結構


數據分析咨詢請掃描二維碼

若不方便掃碼,搜微信號:CDAshujufenxi

數據分析師資訊
更多

OK
客服在線
立即咨詢
日韩人妻系列无码专区视频,先锋高清无码,无码免费视欧非,国精产品一区一区三区无码
客服在線
立即咨詢