Created
          December 11, 2018 11:21 
        
      - 
      
- 
        Save aydinemre/a03e9433ccb063a673c9ed285a7b7315 to your computer and use it in GitHub Desktop. 
    If pandas data frame has multiple format time 
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import pandas as pd | |
| df = pd.DataFrame({"purchase_time": ["19-09-1995 12:14:00.000","12/09/2018 15:34"]}) | |
| df['Timestamp'] = pd.to_datetime(df.purchase_time, format='%d/%m/%Y %H:%M', errors='coerce') | |
| mask = df.Timestamp.isnull() | |
| df.loc[mask, 'Timestamp'] = pd.to_datetime(df[mask]['purchase_time'], format='%d-%m-%Y %H:%M:%S.%f', errors='coerce') | |
| print(df) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment