Guest User

Untitled

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