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
  Grouping in pandas/multi-index data frame Aleqsie 3 662 Jan-06-2024, 03:55 PM
Last Post: deanhystad
  HTML Decoder pandas dataframe column mbrown009 3 1,019 Sep-29-2023, 05:56 PM
Last Post: deanhystad
  Filtering Data Frame, with another value NewBiee 9 1,389 Aug-21-2023, 10:53 AM
Last Post: NewBiee
  Make unique id in vectorized way based on text data column with similarity scoring ill8 0 886 Dec-12-2022, 03:22 AM
Last Post: ill8
Smile How to further boost the data read write speed using pandas tjk9501 1 1,263 Nov-14-2022, 01:46 PM
Last Post: jefsummers
  pandas column percentile nuncio 7 2,434 Aug-10-2022, 04:41 AM
Last Post: nuncio
Thumbs Up can't access data from URL in pandas/jupyter notebook aaanoushka 1 1,861 Feb-13-2022, 01:19 PM
Last Post: jefsummers
  Help with poorly formatted excel data armitron121 1 1,721 Jan-13-2022, 07:31 AM
Last Post: paul18fr
Question Sorting data with pandas TheZaind 4 2,337 Nov-22-2021, 07:33 PM
Last Post: aserian
  pandas: Compute the % of the unique values in a column JaneTan 1 1,776 Oct-25-2021, 07:55 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

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