如何在pandas DataFrame中从2D Raster创建3D数据帧?

时间:2016-02-29 05:54:07

标签: python numpy pandas gis

我有一个numpy代码,它给了我想要的输出:

testing = np.array([arcpy.RasterToNumPyArray(x,nodata_to_value=np.nan) for x in list_arr])
print testing.shape
(365, 25, 23)

我的list_arr变量包含光栅文件的所有名称:

print list_arr
['D:\\BiasCorrection\\Raw_Data\\PeejushData\\BangladeshStationBox025\\2014\\2014_001_025.img','D:\\BiasCorrection\\Raw_Data\\PeejushData\\BangladeshStationBox025\\2014\\2014_002_025.img.......... 

有没有办法在pandas DataFrame中实现类似的输出?而不是使用numpy.array()。

我想输出如下:

print pd.DataFrame([arcpy.RasterToNumPyArray(x,nodata_to_value=np.nan) for x in list_arr]).shape
(365, 25, 23)

但是当我运行上面的命令时,我得到了错误

Traceback (most recent call last):
  File "D:/BiasCorrection/Testing.py", line 35, in <module>
    print pd.DataFrame([arcpy.RasterToNumPyArray(x,nodata_to_value=np.nan) for x in list_arr]).shape
  File "C:\Python27\ArcGIS10.3\lib\site-packages\pandas-0.17.1-py2.7-win32.egg\pandas\core\frame.py", line 281, in __init__
    copy=copy)
  File "C:\Python27\ArcGIS10.3\lib\site-packages\pandas-0.17.1-py2.7-win32.egg\pandas\core\frame.py", line 416, in _init_ndarray
    values = _prep_ndarray(values, copy=copy)
  File "C:\Python27\ArcGIS10.3\lib\site-packages\pandas-0.17.1-py2.7-win32.egg\pandas\core\frame.py", line 5252, in _prep_ndarray
    raise ValueError('Must pass 2-d input')
ValueError: Must pass 2-d input

0 个答案:

没有答案