提取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) # 将数据转化为浮点

提取txt中二维索引变量,并写入nc文件最先出现在Python成神之路

版权声明:
作者:admin
链接:https://www.techfm.club/p/29309.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>