TransWikia.com

Convert '9999-12-31 00:00:00' to 'dd/mm/yyyy' in Pandas

Stack Overflow Asked by Suhas_mudam on November 22, 2021

I have a dataframe containing the column ‘Date’ with value as ‘9999-12-31 00:00:00’. I need to convert it to ‘dd/mm/yyyy’.

import pandas as pd
data = (['9999-12-31 00:00:00'])
df = pd.DataFrame(data, columns=['Date'])

One Answer

Use daily periods by custom function with remove times by split and change format by strftime:

df['Date'] = (df['Date'].str.split()
                        .str[0]
                        .apply(lambda x: pd.Period(x, freq='D'))
                        .dt.strftime('%d/%m/%Y'))
print (df)
         Date
0  31/12/9999

Answered by jezrael on November 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP