3

have a df with values name and age with datetime format

name      age 
 
mark    2002-12-19 18:39

how to reorder the date format with this format

name      age 
 
mark    2002-12-19T18:39:00.000+00:00

1 Answer 1

1

Explicitly set your display format answer

Code below has problems.... the data type of age has been changed to string from datetime64

df = pd.DataFrame([{"name":"mark", "age":pd.to_datetime("2002-12-19 18:39")}])
df["age"] = df["age"].dt.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
print(df.to_string(index=False))
df.dtypes

output

 name                          age
 mark  2002-12-19T18:39:00.000000Z
name    object
age     object
dtype: object
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.