Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 add formatted column to pandas data frame
#1
Hi, I have this example:

timeList = [ '0:00:00', '0:00:15', '9:30:56' ]
totalSecs = 0
for tm in timeList:
    timeParts = [int(s) for s in tm.split(':')]
    totalSecs += (timeParts[0] * 60 + timeParts[1]) * 60 + timeParts[2]
totalSecs, sec = divmod(totalSecs, 60)
hr, min = divmod(totalSecs, 60)
print ("%d:%02d:%02d" % (hr, min, sec))
But rather than summing up the values, I'd like to add the formatted values to a new column that I can then work with. How can I do so?
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  reformatting data frame tkirkland 0 63 Mar-18-2020, 02:17 PM
Last Post: tkirkland
  How to modify data frame row value SriRajesh 0 97 Feb-12-2020, 05:46 PM
Last Post: SriRajesh
  itertuples, new column, datetime, pandas karlito 6 458 Nov-29-2019, 11:07 AM
Last Post: karlito
  Handling escape charters while converting data frame to JSON RahulShukla 0 179 Nov-11-2019, 11:22 AM
Last Post: RahulShukla
  sort values of a column pandas karlito 2 434 Oct-22-2019, 06:11 AM
Last Post: karlito
  pandas DataReader error on all data sources glidecode 5 8,840 Sep-25-2019, 02:10 PM
Last Post: perfringo
  Dropping a column from pandas dataframe marco_ita 6 2,691 Sep-07-2019, 08:36 AM
Last Post: marco_ita
  Loop pandas data frame by position ? Johnse 1 417 Sep-06-2019, 12:26 AM
Last Post: scidam
  pandas data frame dervast 1 336 Aug-28-2019, 12:40 PM
Last Post: ThomasL
  How to drop column in pandas SriMekala 3 698 Aug-26-2019, 06:36 PM
Last Post: snippsat

Forum Jump:


Users browsing this thread: 1 Guest(s)