Guest User

Untitled

a guest
Jan 23rd, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. d = """09:56:07:457 -> 7d
  2. 09:56:07:841 -> 91
  3. 09:56:09:008 -> 02
  4. 09:56:09:233 -> 80
  5. 09:56:09:345 -> 01
  6. 09:56:10:097 -> 80
  7. 09:56:10:448 -> 91
  8. 09:56:11:424 -> 01
  9. 09:56:11:552 -> 01
  10. 09:56:12:351 -> 01
  11. 09:56:12:607 -> 01
  12. 09:56:12:719 -> 01
  13. 09:56:13:711 -> 91
  14. 09:56:14:574 -> a3"""
  15.  
  16. import time
  17. import pandas as pd
  18. import numpy as np
  19.  
  20. import matplotlib.pyplot as plt
  21.  
  22. data = [i.split('->')[0].strip() for i in d.split("n")]
  23.  
  24. #replace : with .
  25. data = [i[:8]+"."+i[9:] for i in data]
  26.  
  27. #add date to beginning
  28. data = ["2001-01-01 " + i for i in data]
  29.  
  30. #make new dataframe and convert strings to datetime index
  31. df = pd.DataFrame({"ms":data})
  32.  
  33. #get milliseconds
  34. df["ms"] = pd.to_datetime(df.ms)
  35.  
  36. #get whole seconds
  37. df["seconds"] = [str(i)[0:19] for i in df["ms"]]
  38. df["seconds"] = pd.to_datetime(df.seconds)
  39. df.index = df.ms
  40. df["bytes"] = [1 for _ in df.seconds]
  41.  
  42. print(df.head())
  43.  
  44. ms seconds bytes
  45. ms
  46. 2001-01-01 09:56:07.457 2001-01-01 09:56:07.457 2001-01-01 09:56:07 1
  47. 2001-01-01 09:56:07.841 2001-01-01 09:56:07.841 2001-01-01 09:56:07 1
  48. 2001-01-01 09:56:09.008 2001-01-01 09:56:09.008 2001-01-01 09:56:09 1
  49. 2001-01-01 09:56:09.233 2001-01-01 09:56:09.233 2001-01-01 09:56:09 1
  50. 2001-01-01 09:56:09.345 2001-01-01 09:56:09.345 2001-01-01 09:56:09 1
  51.  
  52.  
  53. df['string_seconds'] = [str(i) for i in df.seconds]
  54. df = pd.DataFrame(df.string_seconds.value_counts())
  55. df["seconds"] = pd.to_datetime(df.index)
  56. df1 = df.sort_values('seconds')
  57. df1.index = pd.DatetimeIndex(df1.index)
  58.  
  59. df1 = df1.iloc[1:]
  60. df1.resample('1S')
  61. df1.plot(x='seconds', y='string_seconds', figsize=(12,3))
Add Comment
Please, Sign In to add comment