GRDC是国际径流共享网站。下载下来是txt格式如下图:

提供一个python小脚本,输入文件,处理成excel年-月-径流的格式。
import pandas as pd
import numpy as np
pth = 'F:/STA-RUNOFF/AMU/NUSUR.txt' # orignal file
save_pth = 'F:/STA-RUNOFF/AMU/' # out path
save_name = pth.split('/')[-1].split('.')[0]+'.xlsx'
year = []
month = []
day = []
runoff_original = []
runoff_grdc = []
flag = []
result_df = pd.DataFrame()
with open(pth, encoding='gb18030', errors='ignore') as f:
for line in f:
if line.startswith('1'):
line = line.split(';')
yearjunk = line[0].split('-')[0]
monthjunk = line[0].split('-')[1]
dayjunk = line[0].split(&#