Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201919

How can I calculate the duration of a column, grouping by another column (Python or R)

$
0
0

I have a dataframe, df, with the following data:

           ID            DateTime        

           A             12/13/2019 6:35:48PM
           A             12/13/2019 6:35:49PM
           A             12/13/2019 6:35:50PM
           B             12/13/2019 7:00:00PM
           B             12/13/2019 7:00:05PM
           C             12/13/2019 8:00:05PM

Desired outcome:

          ID              Duration

          A                  3 sec
          B                  5 sec
          C                  1 sec

Code I am performing using Python:

df.sum(group_by['ID'])

How can I calculate the duration of a column, grouping by another column?

Any suggestions will help.


Viewing all articles
Browse latest Browse all 201919

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>