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
...