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
  Pandas data frame creation from Kafka Topic vboppa 0 34 Jul-01-2020, 04:23 PM
Last Post: vboppa
  Assigning Column nunique values to another DataFrame column Pythonito 0 113 Jun-25-2020, 05:04 PM
Last Post: Pythonito
  Generate Test data (.csv) using Pandas Ashley 5 258 Jun-15-2020, 02:51 PM
Last Post: jefsummers
  Filter rows by multiple text conditions in another data frame i.e contains strings an Pan 0 255 Jun-09-2020, 06:05 AM
Last Post: Pan
  Pandas - Dynamic column aggregation based on another column theroadbacktonature 0 196 Apr-17-2020, 04:54 PM
Last Post: theroadbacktonature
  Add column to CSV using Pandas nsadams87xx 2 319 Apr-15-2020, 08:41 PM
Last Post: snippsat
  Select column between to dates CSV data PythonJD 0 260 Apr-14-2020, 12:22 PM
Last Post: PythonJD
  Read json array data by pandas vipinct 0 193 Apr-13-2020, 02:24 PM
Last Post: vipinct
  How can I convert time-series data in rows into column srvmig 0 184 Apr-11-2020, 05:40 AM
Last Post: srvmig
  Displaying Result from Data Frame from Function eagle 1 277 Apr-08-2020, 11:58 PM
Last Post: eagle

Forum Jump:


Users browsing this thread: 1 Guest(s)