<jupyter_start><jupyter_text>To_DateTime<jupyter_code>import pandas as pd
dates = ['2020-01-05', 'Jan 5, 2020', '01/05/2020', '2020.01.05', '2020/01/05','20200105']
pd.to_datetime(dates)       # Converting various format to a unique date format
dt = ['2020-01-05 2:30:00 PM', 'Jan 5, 2020 14:30:00', '01/05/2020', '2020.01.05', '2020/01/05','20200105']
pd.to_datetime(dt)  # Possible deal with time<jupyter_output><empty_output><jupyter_text>Bangladeshi style dates with day first<jupyter_code>pd.to_datetime('3-2-2020')    # 2nd March
pd.to_datetime('3-2-2020',dayfirst=True) # 3rd February which is correct<jupyter_output><empty_output><jupyter_text>Custom date time format<jupyter_code>pd.to_datetime('2020$01$05', format='%Y$%m$%d')
pd.to_datetime('2020#01#05', format='%Y#%m#%d')<jupyter_output><empty_output><jupyter_text>Handling invalid dates<jupyter_code>pd.to_datetime(['2017-01-05', 'Jan 6, 2017', 'abc'], errors='ignore') # it doesnot convert into dates if error exist
pd.to_datetime(['2017-01-05', 'Jan 6, 2017', 'abc'], errors='coerce') # Coerce exclude errors, remaining Timestamp<jupyter_output><empty_output><jupyter_text>Epoch Epoch or Unix time means number of seconds that have passed since Jan 1, 1970 00:00:00 UTC time<jupyter_code>current_epoch=1593020453
pd.to_datetime(current_epoch, unit='s') # unit seconds
pd.to_datetime(current_epoch*1000, unit='ms') 
t = pd.to_datetime([current_epoch], unit='s')
t<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup