Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,900 questions

51,831 answers

573 users

How to get the differences times between dates in JSON format string in Python

1 Answer

0 votes
import pandas as pd
 
JSON = [{'part':1, 'time':"2022-08-15 8:17:12"},
        {'part':1, 'time':"2022-08-15 8:18:20"},     
        {'part':2, 'time':"2022-08-15 8:21:14"},
        {'part':3, 'time':"2022-08-15 9:02:03"}]
 
diff = pd.to_datetime(pd.DataFrame(JSON)['time']).diff()
 
print(diff)
 
 
 
'''
run:
 
0               NaT
1   0 days 00:01:08
2   0 days 00:02:54
3   0 days 00:40:49
Name: time, dtype: timedelta64[ns]

'''

 



answered Sep 23, 2022 by avibootz
edited Sep 23, 2022 by avibootz
...