Skip to content

Instantly share code, notes, and snippets.

@walkerjeffd
Created February 10, 2014 14:48
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walkerjeffd/8917230 to your computer and use it in GitHub Desktop.
Save walkerjeffd/8917230 to your computer and use it in GitHub Desktop.
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