提取txt中二维索引变量,并写入nc文件
import pandas as pd
import numpy as np
import netCDF4 as nc
# 读取txt文件
file = r'D:/Desktop/root/runoff/runoff.txt'
with open(file, 'r') as f:
data = pd.read_table(file, sep="/s+", header=None, names=["x", "y", "dat"], low_memory=False) # 读取txt并分隔
data = pd.DataFrame(data)
duplicate = data.duplicated(subset=['x', 'y'], keep=False) # 按"x","y"提取重复索引
duplicate_data = data.loc[duplicate, :]
duplicate_data['dat'] = duplicate_data['dat'].astype(float) # 将数据转化为浮点
共有 0 条评论