DataFrame的基本操作

來源:互聯網
上載者:User

標籤:style   blog   http   color   width   2014   

DataFrame的基本操作

1,選擇

(1),Select column

In [11]: df[‘a‘]Out[11]:0   -1.3552631    0.0108882    1.5995833    0.0045654    0.460270Name: a, dtype: float64
(2),Select row by label
In [15]: df.loc[1]Out[15]:a    0.010888b   -0.900427c   -0.397198Name: 1, dtype: float64

 

(3) Select row by integer location

In [19]: df.iloc[1]Out[19]:a    0.010888b   -0.900427c   -0.397198Name: 1, dtype: float64
(4) Slice rows
In [24]: df[1:3]Out[24]:          a         b         c1  0.010888 -0.900427 -0.3971982  1.599583  0.662713  0.943103

(5) Select rows by boolean vector

In [27]: df[df[‘a‘]>0.5]Out[27]:          a         b         c2  1.599583  0.662713  0.943103

2,刪除

In [28]: del df[‘a‘]In [29]: dfOut[29]:          b         c0  1.451534 -0.4977931 -0.900427 -0.3971982  0.662713  0.9431033 -0.505622  1.1569414  0.333584 -1.260798

 

In [32]: df.pop(‘b‘)Out[32]:0    1.4515341   -0.9004272    0.6627133   -0.5056224    0.333584Name: b, dtype: float64In [33]: dfOut[33]:          c0 -0.4977931 -0.3971982  0.9431033  1.1569414 -1.260798
3,插入
In [35]: df[‘e‘]=[‘e‘,‘w‘,‘t‘,‘e‘,‘d‘]In [36]: dfOut[36]:          c  e0 -0.497793  e1 -0.397198  w2  0.943103  t3  1.156941  e4 -1.260798  d

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.