Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tools for processing GHCND text files
import pandas as pd
import csv
colspecs = [(0,11), (12,20), (21,30), (31,35), (36,40), (41,45)]
df = pd.read_fwf('ghcnd-inventory.txt', colspecs=colspecs, header=None, index_col=None)
df.columns = ["ID", "LATITUDE", "LONGITUDE", "ELEMENT", "FIRSTYEAR", "LASTYEAR"]
df.set_index("ID", inplace=True)
df.to_csv('ghcnd-inventory.csv', quoting=csv.QUOTE_NONNUMERIC)
import pandas as pd
import csv
colspecs = [(0,11), (12,20), (21,30), (31,37), (38,40), (41,71), (72,75), (76,79), (80,85)]
df = pd.read_fwf('ghcnd-stations.txt', colspecs=colspecs, header=None, index_col=None)
df.columns = ["ID", "LATITUDE", "LONGITUDE", "ELEVATION", "STATE", "NAME", "GSNFLAG", "HCNFLAG", "WMOID"]
df.set_index("ID", inplace=True)
df.to_csv('ghcnd-stations.csv', quoting=csv.QUOTE_NONNUMERIC)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment