Reputation: 21
I want to change the format of "Date" column from 10/15/2019 to m/d/y format.
tax['AsOfdate']= pd.to_datetime(tax['date'])
How do I do it?
Upvotes: 2
Views: 123
Reputation: 1072
Pandas to_datetime
function accepts a format command which accepts strftime notation.
Pandas docs: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html
Strftime docs: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior
m/d/y notation would be:
tax['AsOfdate']= pd.to_datetime(tax['date'], format='%m/%d/%y)
Assuming you want everything zero padded with two digits like 01/01/19 for January first 2019. If you need something else, the strftime formatting link shows all the codes that let you choose padding or not, four-digit year or two-digit, and so on.
Upvotes: 0
Reputation: 2569
like this, and here is the documentation.
tax['AsOfdate']= pd.to_datetime(tax['date'], format="%m/%d/%Y" )
Upvotes: 1
Reputation: 95
Here is an example with today's date formatting:
from datetime import date
today = date.today()
new_format = today.strftime("%m/%d/%y")
print(today, new_format)
Upvotes: 0