Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- items = [
- datetime.datetime(2018, 3, 19, 16, 51, 48),
- datetime.datetime(2018, 3, 19, 17, 25, 19),
- datetime.datetime(2018, 3, 20, 6, 33, 35),
- datetime.datetime(2018, 3, 19, 23, 21, 35),
- datetime.datetime(2018, 3, 19, 15, 8, 41),
- datetime.datetime(2018, 3, 19, 21, 44, 16),
- datetime.datetime(2018, 3, 19, 18, 21, 28),
- datetime.datetime(2018, 3, 20, 7, 20, 22),
- datetime.datetime(2018, 3, 20, 11, 15, 43)
- ]
- import pandas as pd
- def _generate_timeseries(items, start_ts, end_ts):
- # add start/end times to the data
- items.insert(0, start_ts)
- items.append(end_ts)
- # value each datetime as one occurrence
- data = [1 for x in range(len(items))]
- timeseries = pd.Series(data, index=items)
- hourly_data = timeseries.resample('H').sum()
- timeline = hourly_data.tolist()
- return [{'mentions': x} for x in timeline[1:-1]]
- timeline =[
- {'mentions': 4}, {'mentions': 2}, {'mentions': 1}, {'mentions': 0}, {'mentions': 3}, {'mentions': 2}, {'mentions': 2}, {'mentions': 1}, {'mentions': 1}, {'mentions': 0}, {'mentions': 1}, {'mentions': 0}, {'mentions': 14}, {'mentions': 1}, {'mentions': 4}, {'mentions': 2}, {'mentions': 3}, {'mentions': 2}, {'mentions': 1}, {'mentions': 2}, {'mentions': 6}, {'mentions': 2}, {'mentions': 2}
- ]
Add Comment
Please, Sign In to add comment