Python Forum
add formatted column to pandas data frame
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pandas: summing columns conditional on the column labels ddd2332 0 411 Sep-10-2020, 05:58 PM
Last Post: ddd2332
  how to filter data frame dynamically with the columns psahay 0 225 Aug-24-2020, 01:10 PM
Last Post: psahay
  Dropping Rows From A Data Frame Based On A Variable JoeDainton123 1 319 Aug-03-2020, 02:05 AM
Last Post: scidam
  How to shift data frame rows of specified column Mekala 0 486 Jul-21-2020, 02:42 PM
Last Post: Mekala
  Filter data based on a value from another dataframe column and create a file using lo pawanmtm 1 418 Jul-15-2020, 06:20 PM
Last Post: pawanmtm
  HELP- DATA FRAME INTO TIME SERIES- BASIC bntayfur 0 276 Jul-11-2020, 09:04 PM
Last Post: bntayfur
  pandas read_csv can't handle missing data mrdominikku 0 399 Jul-09-2020, 12:26 PM
Last Post: mrdominikku
  Pandas DataFrame and unmatched column sritsv19 0 496 Jul-07-2020, 12:52 PM
Last Post: sritsv19
  Pandas data frame creation from Kafka Topic vboppa 0 247 Jul-01-2020, 04:23 PM
Last Post: vboppa
  Assigning Column nunique values to another DataFrame column Pythonito 0 307 Jun-25-2020, 05:04 PM
Last Post: Pythonito

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020