我是 Pandas 新手。我尝试做一个例子,我有一个三维点网格,网格的尺寸是N1 x N2 x N3。
网格中的每个点都包含一些数据( numpy.ndarray
、 float
数字等)。例如:在 Point(0,0,0): 'date' = 18
, 'temperature array' = numpy.array([[1,2,3], [4,5,6]])
.
现在我的目标是创建一个 pandas“表”(我来了 pandas.Panel
),这样当我打电话 table['date'][Point(0,0,0)]
时,结果应返回:18
当我调用table['temperature array'][Point(0,0,0)]
时,它返回 numpy.array([[1,2,3], [4,5,6]])
.
你能发布一个简单的例子吗,这对我有很大帮助。
谢谢
最佳答案
Panel4D 可能就是您正在寻找的。它本质上是从前 3 个维度创建一个多级索引。
import pandas as pd
import numpy as np
# 100 x 100 x 100 x 3 array
data = np.random.randn(100,100,100,3)
data[0,0,0]
# out[]:
# array([ 0.85284721, -0.04883839, -0.09375558])
table = pd.Panel4D(data)
table.ix[0,0,0]
# out[]:
# minor
# 0 0.852847
# 1 -0.048838
# 2 -0.093756
# Name: 0, dtype: float64
关于python - Pandas Panel 作为 numpy 多维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21552508/