def indexed_temperatures(self, index, unit, allow_mixed_frequency=False):
''' Return average temperatures over the given index.
Parameters
----------
index : pandas.DatetimeIndex
Index over which to supply average temperatures.
The :code:`index` should be given as either an hourly ('H') or
daily ('D') frequency.
unit : str, {"degF", "degC"}
Target temperature unit for returned temperature series.
Returns
-------
temperatures : pandas.Series with DatetimeIndex
Average temperatures over series indexed by :code:`index`.
'''
if index.shape == (0,):
return pd.Series([], index=index, dtype=float)
self._verify_index_presence(index) # fetches weather data if needed
if index.freq is not None:
freq = index.freq
else:
try:
freq = pd.infer_freq(index)
except ValueError:
freq = None
if freq == 'D':
return self._daily_indexed_temperatures(index, unit)
elif freq == 'H':
return self._hourly_indexed_temperatures(index, unit)
elif allow_mixed_frequency:
return self._mixed_frequency_indexed_temperatures(index, unit)
else:
message = 'DatetimeIndex with unknown frequency not supported.'
raise ValueError(message)
评论列表
文章目录