Python Forum
Simple String to Time within a pandas dataframe
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple String to Time within a pandas dataframe
#1
Hi

I have a data frame with strings that look like date and another column of time.
What would be the best way to convert them to actual datetime objects (or to two objects of date and time) ?

Note : After looking online, it seems I should be able to use the datetime.time.strptime function, however it doesnt appear to be a proper method/function (ie not listed). strftime i...

Looking to update the column (data imported from csv text file via pandas.read_csv)

Point to something that works would be great...

Data frame looks like :
date atime other columns
13-06-2019 10:00 blah blah
12-06-2019 09:15 blah blah blah

Thanks in advance
Reply
#2
You can use pd.to_datetime utility function, e.g.
import pandas as pd
df = pd.DataFrame({'atime': ['13-06-2019 10:00', '12-06-2019 09:15'], 'x': [1, 2]})
df.atime = pd.to_datetime(df.atime)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question [Solved] Formatting cells of a pandas dataframe into an OpenDocument ods spreadsheet Calab 1 688 Mar-01-2025, 04:51 AM
Last Post: Calab
  Find duplicates in a pandas dataframe list column on other rows Calab 2 2,202 Sep-18-2024, 07:38 PM
Last Post: Calab
  Find strings by index from a list of indexes in a different Pandas dataframe column Calab 3 1,640 Aug-26-2024, 04:52 PM
Last Post: Calab
  Add NER output to pandas dataframe dg3000 0 1,161 Apr-22-2024, 08:14 PM
Last Post: dg3000
  Parsing and summing time deltas (duration) onto bar + pie charts using pandas - - DRY Drone4four 2 2,064 Feb-10-2024, 06:04 PM
Last Post: Drone4four
  HTML Decoder pandas dataframe column mbrown009 3 2,707 Sep-29-2023, 05:56 PM
Last Post: deanhystad
  Pandas read csv file in 'date/time' chunks MorganSamage 4 3,027 Feb-13-2023, 11:24 AM
Last Post: MorganSamage
  Use pandas to obtain cartesian product between a dataframe of int and equations? haihal 0 2,024 Jan-06-2023, 10:53 PM
Last Post: haihal
  Pandas Dataframe Filtering based on rows mvdlm 0 2,085 Apr-02-2022, 06:39 PM
Last Post: mvdlm
  Pandas dataframe: calculate metrics by year mcva 1 3,434 Mar-02-2022, 08:22 AM
Last Post: mcva

Forum Jump:

User Panel Messages

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