SHARE
TWEET

Python - pandas - timedelta

furas Jul 6th, 2018 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pandas as pd
  2.  
  3. text = '''0 00:05:00
  4. 1 00:20:00
  5. 2 00:35:00
  6. 3 05:23:00
  7. 4 05:38:00
  8. 5 05:53:00
  9. 6 06:08:00
  10. 7 06:18:00
  11. 8 06:28:00
  12. 9 06:38:00
  13. 10 06:48:00
  14. 11 06:54:00
  15. 12 07:00:00
  16. 13 07:06:00
  17. 14 07:11:00
  18. 15 07:16:00
  19. 16 07:21:00
  20. 17 07:26:00'''
  21.  
  22. data = [line.split(' ') for line in text.splitlines()]
  23.  
  24. print('type:', df['time'].dtype)
  25.  
  26. df = pd.DataFrame(data, columns=['index', 'time'])
  27.  
  28. df['timedelta'] = pd.to_timedelta(df['time']).dt.seconds
  29.  
  30. print(df['timedelta'])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top