-2

[Still unanswered]

Hello I recently identified a solution to convert a time format into hours and minutes.

from datetime import datetime

x = datetime.strptime('2017-01-01T19:33:28+0000', '%Y-%m-%dT%H:%M:%S%z')\ .strftime('%H:%M')

However I can only do this for one value in a column. How do you apply it to all values in an entire column?

Here are the column values I want to convert: image

Edit 1: Here is my failed attempt The error says "TypeError: strptime() argument 1 must be str, not Series"

Edit 2: Here is my 2nd attempt This error says SyntaxError: unexpected character after line continuation character

and also NameError: name 'pandas' is not defined (even though I'm using pandas which is confusing?)

Thanks!

Pallison
  • 7
  • 3

1 Answers1

0

It's always better work with pandas when you work with data.

When you convert your data into a dataframe_pandas (https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html) , you can just:

import pandas as pd

df --> dataframe

df['column']=pd.to_datetime(df['column'], format=...)

This post can help you Convert Pandas Column to DateTime