pandas的劄記

來源:互聯網
上載者:User

標籤:

匯入匯出資料

在匯入,匯出DataFrame資料時,會用到各種格式,分為

可參照IO Tools 分類。

如果想要儲存為ascii文本則可以使用to_csv,可以對是否儲存索引(行號)等參數進設定。

調換colums順序

若未經處理資料是這樣的:

In [6]: dfOut[6]:          0         1         2         3         4      mean0  0.445598  0.173835  0.343415  0.682252  0.582616  0.4455431  0.881592  0.696942  0.702232  0.696724  0.373551  0.6702082  0.662527  0.955193  0.131016  0.609548  0.804694  0.6325963  0.260919  0.783467  0.593433  0.033426  0.512019  0.4366534  0.131842  0.799367  0.182828  0.683330  0.019485  0.3633715  0.498784  0.873495  0.383811  0.699289  0.480447  0.5871656  0.388771  0.395757  0.745237  0.628406  0.784473  0.5885297  0.147986  0.459451  0.310961  0.706435  0.100914  0.3451498  0.394947  0.863494  0.585030  0.565944  0.356561  0.5531959  0.689260  0.865243  0.136481  0.386582  0.730399  0.561593In [7]: cols = df.columns.tolist()In [8]: colsOut[8]: [0L, 1L, 2L, 3L, 4L, ‘mean‘]
View Code

通過調換columns更改順序

In [12]: cols = cols[-1:] + cols[:-1] In [13]: colsOut[13]: [‘mean‘, 0L, 1L, 2L, 3L, 4L]

 

進而可以達到如下效果

In [16]: df = df[cols]  #    OR    df = df.ix[:, cols]In [17]: dfOut[17]:       mean         0         1         2         3         40  0.445543  0.445598  0.173835  0.343415  0.682252  0.5826161  0.670208  0.881592  0.696942  0.702232  0.696724  0.3735512  0.632596  0.662527  0.955193  0.131016  0.609548  0.8046943  0.436653  0.260919  0.783467  0.593433  0.033426  0.5120194  0.363371  0.131842  0.799367  0.182828  0.683330  0.0194855  0.587165  0.498784  0.873495  0.383811  0.699289  0.4804476  0.588529  0.388771  0.395757  0.745237  0.628406  0.7844737  0.345149  0.147986  0.459451  0.310961  0.706435  0.1009148  0.553195  0.394947  0.863494  0.585030  0.565944  0.3565619  0.561593  0.689260  0.865243  0.136481  0.386582  0.730399
View Code

 (參考來源)

pandas的劄記

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.