[問題] pandas panel slicing問題
今天我在處理資料的時候,遇到了一個很有趣的問題,範例程式碼如下:
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
推
05/19 22:17, , 1F
05/19 22:17, 1F
→
05/20 00:02, , 2F
05/20 00:02, 2F