作者gozule (好冷啊~~)
看板Python
標題[問題] pandas panel slicing問題
時間Tue May 19 16:55:56 2015
今天我在處理資料的時候,遇到了一個很有趣的問題,範例程式碼如下:
import numpy as np
a = np.random.rand(2,3,4)
print a[0,:,:].shape #(3,4)
print a[:,0,:].shape #(2,4)
print a[:,:,0].shape #(2,3)
import pandas as pd
p = pd.Panel(a)
print p[0,:,:].shape #(3,4)
print p[:,0,:].shape #(4,2)
print p[:,:,0].shape #(3,2)
為何panel沿2nd (major-axis)與3rd(minor axis) dimension slicing的行為
會與單純使用numpy不同?
雖然是可以用transpose處理資料,但是不一致的行為會讓人混亂,請問是否有
不用transpose從panel中取出與numpy相同維度資料的方法,謝謝。
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.238.136.219
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1432025759.A.30A.html
推 Fungshui: p.values就會跟a一樣了 05/19 22:17
→ gozule: 試了一下,p.values[:,0,:]正確,p[:,0,:].values同(4,2) 05/20 00:02