1 回答

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個(gè)贊
解決了
我查看了 xarray readthedocs 頁(yè)面,在 open_mfdataset 頁(yè)面中看到了這個(gè)簡(jiǎn)介。
路徑(str 或 sequence)——“path/to/my/files/*.nc”形式的字符串 glob 或要打開的文件的顯式列表。路徑可以作為字符串或 pathlib 路徑給出。如果需要沿多個(gè)維度進(jìn)行連接,則路徑必須是嵌套的列表列表(有關(guān)詳細(xì)信息,請(qǐng)參閱 manual_combine)。(字符串 glob 將擴(kuò)展為一維列表。)
因此,我通過了一個(gè)列表
更新和工作代碼
import xarray as xr
from datetime import timedelta, date, datetime
import pandas as pd
import numpy as np
# **************
# Date Ranges
# **************
def daterange(start_date, end_date):
for n in range(int((end_date - start_date).days)):
yield start_date + timedelta(n)
# Start & End Date
start_date = date(2019, 1, 1)
end_date = date(2019, 1, 31)
# Empty List
filepath = 'C:\\Users\\USER\\FILES\\'
filelist = []
# Loop through all MERRA2 files and add the ones we need to the list
for single_date in daterange(start_date, end_date):
YYYY = single_date.strftime("%Y")
MM = single_date.strftime("%m")
DD = single_date.strftime("%d")
filename = filepath + YYYY + MM + DD + '_data_Nx.nc'
filelist.append(filename)
# Merge via X-Array and export to csv
ds = xr.open_mfdataset(filelist, combine='by_coords')
df = ds.to_dataframe()
df.to_csv('export.csv', index=True)
添加回答
舉報(bào)