def markGaps(self):
"""Produces dictionary of list of gaps in time series data based on the presence of nan values;
used for gantt plotting
:returns: dateranges; a dictionary with station names as keys and lists of begin and end dates as values
"""
df = self.data
stations = self.stations
dateranges = {}
for station in stations:
dateranges[station] = []
first = df.ix[:, station].first_valid_index()
last = df.ix[:, station].last_valid_index()
records = df.ix[first:last, station]
#dateranges[station].append(pd.to_datetime(first))
for i in range(len(records) - 1):
if pd.isnull(records[i + 1]) and pd.notnull(records[i]):
dateranges[station].append(pd.to_datetime(records.index)[i])
elif pd.isnull(records[i]) and pd.notnull(records[i + 1]):
dateranges[station].append(pd.to_datetime(records.index)[i])
dateranges[station].append(pd.to_datetime(last))
return dateranges
评论列表
文章目录