如何解决如何在python中创建一个充满NaT的时间矩阵?
我想创建一个空的 3D 时间矩阵(具有已知大小),稍后我将使用 pd.dateTimeIndex 或 pd.timestamp 列表在循环中填充该矩阵。有没有简单的方法?
这不起作用:
timeMatrix = np.empty( shape=(100,1000,2) )
timeMatrix[:] = pd.NaT
我可以不用第二行,但是 timeMatrix 中的数字变成了 10^18 个数字。
timeMatrix = np.empty( shape=(100,2) )
for pressureLevel in levels:
timeMatrix[ i_airport,0:varyingNumberBelow1000,pressureLevel ] = dates_datetimeindex
谢谢
解决方法
df = pd.DataFrame(index=range(10),columns=range(10),dtype="datetime64[ns]")
print(df)
打印:
0 1 2 3 4 5 6 7 8 9
0 NaT NaT NaT NaT NaT NaT NaT NaT NaT NaT
1 NaT NaT NaT NaT NaT NaT NaT NaT NaT NaT
2 NaT NaT NaT NaT NaT NaT NaT NaT NaT NaT
3 NaT NaT NaT NaT NaT NaT NaT NaT NaT NaT
4 NaT NaT NaT NaT NaT NaT NaT NaT NaT NaT
5 NaT NaT NaT NaT NaT NaT NaT NaT NaT NaT
6 NaT NaT NaT NaT NaT NaT NaT NaT NaT NaT
7 NaT NaT NaT NaT NaT NaT NaT NaT NaT NaT
8 NaT NaT NaT NaT NaT NaT NaT NaT NaT NaT
9 NaT NaT NaT NaT NaT NaT NaT NaT NaT NaT
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。