Split Datetime Column into a Date and Time Python -


hey have seen several questions this, however, have yet successful solve problem.

i have single column time in format:

2014-07-17 00:59:27.400189+00

i want split 2 columns, date , hour.

i used

 posts['date']=pd.to_datetime(posts['time'],format='%y-%m-%d %h:%m:%s') 

however, error

 valueerror: unconverted data remains: 400189+00 

i not sure label last bit of information. tried added %o received error

 valueerror: 'o' bad directive in format '%y-%m-%d %h:%m:%s.%o' 

any ideas on how can split these 2 values 2 columns?

thanks!

the following worked me:

in [18]:  import pandas pd df = pd.dataframe({'date':['2014-07-17 00:59:27.400189+00']}) df.dtypes out[18]: date    object dtype: object in [19]:  df['date'] = pd.to_datetime(df['date']) df.dtypes out[19]: date    datetime64[ns] dtype: object in [20]:  df['time'],df['date']= df['date'].apply(lambda x:x.time()), df['date'].apply(lambda x:x.date()) df out[20]:          date             time 0  2014-07-17  00:59:27.400189  [1 rows x 2 columns] 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -