我有一些12小时间隔的四维水文数据。我想用以下代码计算出它的日平均值:
>>> InNcFile = Dataset ( InputFile, 'r' )
>>> Time = InNcFile.variables['time'][:]
>>> Latitude = InNcFile.variables['lat'][:]
>>> Longitude = InNcFile.variables['lon'][:]
>>> ZLevel = InNcFile.variables['lvl'][:]
>>> SM = InNcFile.variables['sm'][:,:,:,:]
>>> DateTime = map ( lambda x: datetime.strptime ( x, '%Y%m%d%H%M' ), Time )
>>> df = pandas.Panel4D ( SM, labels = DateTime, items = ZLevel, major_axis = Latitude, minor_axis = Longitude )
>>> SM.shape
(21, 4, 769, 1024)
>>> df_SMoist.shape
(21, 4, 769, 1024)
>>> df_MeanSM = df_SMoist.resample ( 'D', how = 'mean', axis = 0 )
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/projects/access/apps/pythonlib/pandas/0.12.0/pandas-0.12.0-py2.7-linux-x86_64.egg/pandas/core/generic.py", line 290, in resample
return sampler.resample(self)
File "/projects/access/apps/pythonlib/pandas/0.12.0/pandas-0.12.0-py2.7-linux-x86_64.egg/pandas/tseries/resample.py", line 83, in resample
rs = self._resample_timestamps(obj)
File "/projects/access/apps/pythonlib/pandas/0.12.0/pandas-0.12.0-py2.7-linux-x86_64.egg/pandas/tseries/resample.py", line 209, in _resample_timestamps
grouped = obj.groupby(grouper, axis=self.axis)
File "/projects/access/apps/pythonlib/pandas/0.12.0/pandas-0.12.0-py2.7-linux-x86_64.egg/pandas/core/panelnd.py", line 111, in func
raise NotImplementedError
NotImplementedError
现在,如果我把SM数组变成三维的,只有一个ZLevel(也就是说,使用Panel而不是Panel4D),它可以正常工作。你能帮我找出我做错了什么吗?在
谢谢。在
Panel4D
s还没有(还?)像DataFrames
一样拥有功能丰富的API。你可以的 通过将四维数据加载到二维数据来解决这个问题 数据帧with a MultiIndex。在例如,如果您的}的外观
像这样:
SM
、dates
、zlevel
、latitude
和{然后,您可以使用这样的多索引构建一个数据帧:
^{pr2}$要按日期重新采样,索引必须是DatetimeIndex、TimedeltaIndex或PeriodIndex,而不是多重索引。因此,我们需要将}索引级别移到列中:
zlevel
、lat
和{现在
df
看起来像现在我们可以重新采样日期:
相关问题 更多 >
编程相关推荐