python - Convert date in form of "%Y%M%D" to "%Y%M%D%H%M%S" in pandas -


below dataframe

   date time   open   high    low  close     volume  adj close 0 2012-05-15  15.90  16.06  15.80  16.02  134454.78       0.08 1 2012-05-16  16.00  16.00  15.75  15.76  150305.11      -0.26 2 2012-05-17  15.80  15.97  15.76  15.94  133389.98       0.18 3 2012-05-18  15.80  15.91  15.66  15.72  157863.19      -0.22 4 2012-05-21  15.72  15.84  15.70  15.77   85694.85       0.05 

you see in column of "date time", data in form"%y%m%d" want convert them "%y%m%d%h%m$s" example 2012-05-17 00:00:00

thanks!

if not need convert datetime, can call apply , use datetime.strftime formatting:

in [212]:  df['date'] = pd.to_datetime(df['date']) df['date'] out[212]: index 0   2012-05-15 1   2012-05-16 2   2012-05-17 3   2012-05-18 4   2012-05-21 name: date, dtype: datetime64[ns] in [213]:  import datetime dt df['date'] = df['date'].apply(lambda x: dt.datetime.strftime(x, '%y-%m-%d %h:%m:%s')) df['date'] out[213]: index 0    2012-05-15 00:00:00 1    2012-05-16 00:00:00 2    2012-05-17 00:00:00 3    2012-05-18 00:00:00 4    2012-05-21 00:00:00 name: date, dtype: object 

note converts dtype datetime str


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -