Reputation:
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
Upvotes: 3
Views: 64
Reputation: 31236
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
Upvotes: 1