Skip to content

Instantly share code, notes, and snippets.

@robintw
Created July 17, 2016 10:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save robintw/569ce05e01f405c7e9744d651123fbb6 to your computer and use it in GitHub Desktop.
Save robintw/569ce05e01f405c7e9744d651123fbb6 to your computer and use it in GitHub Desktop.
Simple function to read AERONET data into a Pandas DataFrame
import pandas as pd
def read_aeronet(filename):
"""Read a given AERONET AOT data file, and return it as a dataframe.
This returns a DataFrame containing the AERONET data, with the index
set to the timestamp of the AERONET observations. Rows or columns
consisting entirely of missing data are removed. All other columns
are left as-is.
"""
dateparse = lambda x: pd.datetime.strptime(x, "%d:%m:%Y %H:%M:%S")
aeronet = pd.read_csv(filename, skiprows=4, na_values=['N/A'],
parse_dates={'times':[0,1]},
date_parser=dateparse)
aeronet = aeronet.set_index('times')
del aeronet['Julian_Day']
# Drop any rows that are all NaN and any cols that are all NaN
# & then sort by the index
an = (aeronet.dropna(axis=1, how='all')
.dropna(axis=0, how='all')
.rename(columns={'Last_Processing_Date(dd/mm/yyyy)': 'Last_Processing_Date'})
.sort_index())
return an
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment