Pandas df converting timestamp column value format

zsad512

I have a dataframe with the dates column listed in the following format 2017/08/23 and I would like to convert all values in the column to the following format:

2011-09-13
00:00:00

What is the best way to do this?

Scott Boston

Use pd.to_datetime from Pandas:

import pandas as pd
from io import StringIO

date_string = StringIO("""date
2017/08/23
2017/08/24
2017/08/25""")

df = pd.read_csv(date_string)

pd.to_datetime(df['date'])

Output:

0   2017-08-23
1   2017-08-24
2   2017-08-25
Name: date, dtype: datetime64[ns]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

add a 'now' timestamp column to a pandas df

Converting sav to pandas df misses last column

Converting time format for column of pandas dataframe

converting the column of a dataframe into a timestamp

Converting timestamp format in dataframe

Pandas/Python Filtering a DF for column value

Pandas: converting timestamp into datetime

Filtering Pandas df by date and another column value

Replace value in Pandas DF column, based on a condition

Converting timestamp column in custom string format to seconds in python

Converting and inserting timestamp in pandas

Converting a pandas column to datetime with inconsistent format

pandas: How to format timestamp axis labels nicely in df.plt()?

Converting column into proper timestamp using pandas read_csv

Assign Column where equal to value - pandas df

New column value based on two timestamp columns in df

Pandas column - converting string into specific date format

Pandas, converting date time column format's changes the column type

Converting an integer value in pandas column to string

Converting a weekly forecast (Pandas df) into monthly format

Converting timestamp to date and keeping only date in a list inside pandas column

Converting pandas df column of values to uniqueidentifiers

Get pandas df column value distribution

Pandas df swap column value

pandas merge df based of 2 column value

Pandas: Check if value in one df exists in any column of another DF

Pandas: Check if value in one df exists in any column of another DF

Pandas df column has some value as dict

Converting multi column header df from wide to long format in python