Simple String to Time within a pandas dataframe - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Simple String to Time within a pandas dataframe (/thread-19119.html) |
Simple String to Time within a pandas dataframe - Ecniv - Jun-13-2019 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 RE: Simple String to Time within a pandas dataframe - scidam - Jun-14-2019 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) |