日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Series

發布時間:2025/4/5 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Series 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

構造Series

obj=Series([4,5,-7,7])obj Out[140]: 0 4 1 5 2 -7 3 7 dtype: int64obj.index Out[141]: RangeIndex(start=0, stop=4, step=1)obj.values Out[142]: array([ 4, 5, -7, 7], dtype=int64)

構造同時指定索引

obj2=Series([4,5,-7,7],index=['a','b','c','d'])obj2 Out[144]: a 4 b 5 c -7 d 7 dtype: int64

讀取

obj2.a Out[148]: 4obj2['a'] Out[149]: 4

數學運算

obj2[obj2>0] Out[150]: a 4 b 5 d 7 dtype: int64obj2*2 Out[151]: a 8 b 10 c -14 d 14 dtype: int64np.exp(obj2) Out[152]: a 54.598150 b 148.413159 c 0.000912 d 1096.633158 dtype: float64 'b' in obj2 Out[153]: True't' in obj2 Out[154]: False

由字典變成Series

sdata={'ohio':3500,'texas':71000,'oregon':16000,'utah':500}obj3=Series(sdata)obj3 Out[159]: ohio 3500 oregon 16000 texas 71000 utah 500 dtype: int64

替換字典的index,與California 對應的sdata 沒有,顯示是NaN

states=['california','ohio','oregon','texas']sdata={'ohio':3500,'texas':71000,'oregon':16000,'utah':500}obj4=Series(sdata,index=states)obj4 Out[170]: california NaN ohio 3500.0 oregon 16000.0 texas 71000.0 dtype: float64

判斷數據是否缺失

pd.isnull(obj4) Out[171]: california True ohio False oregon False texas False dtype: boolpd.notnull(obj4) Out[172]: california False ohio True oregon True texas True dtype: bool

判斷缺失的另一種表達

obj4.notnull() Out[176]: california False ohio True oregon True texas True dtype: boolobj4.isnull() Out[177]: california True ohio False oregon False texas False dtype: bool obj3 Out[18]: ohio 3500 oregon 16000 texas 71000 utah 500 dtype: int64obj4 Out[19]: california NaN ohio 3500.0 oregon 16000.0 texas 71000.0 dtype: float64obj3+obj4 Out[20]: california NaN ohio 7000.0 oregon 32000.0 texas 142000.0 utah NaN dtype: float64 obj4.name='population'obj4.index.name='state'obj4 Out[30]: state california NaN ohio 3500.0 oregon 16000.0 texas 71000.0 Name: population, dtype: float64 obj=Series([4,7,-5,3])obj Out[43]: 0 4 1 7 2 -5 3 3 dtype: int64obj.index=['bob','steve','jeff','ryan']obj Out[45]: bob 4 steve 7 jeff -5 ryan 3 dtype: int64 《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的Series的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。