Skip to content

Instantly share code, notes, and snippets.

@bstadlbauer
Last active October 9, 2019 17:17
Show Gist options
  • Save bstadlbauer/473b525a21241632d82680a12cd93851 to your computer and use it in GitHub Desktop.
Save bstadlbauer/473b525a21241632d82680a12cd93851 to your computer and use it in GitHub Desktop.
import datetime
import pandas as pd
_TIMESTAMP_FORMAT = '%Y-%m-%d %H:%M'
time_ranges = [
(datetime.datetime(2019, 6, 16, 14, 2), datetime.datetime(2019, 6, 17, 7, 2)),
(datetime.datetime(2019, 8, 15, 12, 30), datetime.datetime(2019, 8, 17, 8, 30))
]
# DataFrame for testing
# rdfAnd = pd.DataFrame.from_records(
# ((datetime.datetime(2019, 6, 16, 17, 00), 11), ),
# columns=['date_time', 'Intensity']
# )
records = []
for start_timestamp, end_timestamp in time_ranges:
daterange_string = f'From {start_timestamp.strftime(_TIMESTAMP_FORMAT)} to {end_timestamp.strftime(_TIMESTAMP_FORMAT)}'
accumulated_intensity = total_rain = rdfAnd[
(rdfAnd['date_time'] >= start_timestamp) &
(rdfAnd['date_time'] <= end_timestamp)
]['Intensity'].sum()
records.append((daterange_string, accumulated_intensity))
intensity_ranges = pd.DataFrame.from_records(records, columns=['daterange', 'accumulated_intensity'])
print(intensity_ranges)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment