Converting epoch to string in format yyyy-mm-dd, or maybe it is not necessary

Pavol Lisy pavol.lisy at gmail.com
Wed Jun 14 23:58:50 EDT 2017


(I am not very familiar with panda too!)

In case of his data he needs to set unit to 's'

df['dt'] = pd.to_datetime(df.epoch,unit='s')

It return utc time from epoch, so maybe this is what he could use ->

df['dt'] = df.epoch.apply(time.ctime)

or something like (if he needs strings) ->

df['dt'] = df.epoch.apply(lambda a:time.strftime('%Y-%m-%d %H:%M:%S',
time.localtime(a))
df['dt'] = df.epoch.apply(lambda a:time.strftime('%Y-%m-%d %H:%M:%S',
time.gmtime(a))  # if utc is desired

On 6/15/17, Andre Müller <gbs.deadeye at gmail.com> wrote:
> I'm not familar with pandas.
>
> If you look on stackoverfolow you'll find this solution:
>
> df.epoch = pd.to_datetime(df.epoch)
> https://stackoverflow.com/questions/17134716/convert-dataframe-column-type-from-string-to-datetime
>
> But in this case, it's not a plain string, then it's a datetime object.
>
> Greetings
> Andre
> --
> https://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list