Pandas: Using Unix epoch timestamp as Datetime index

前端 未结 3 1218
误落风尘
误落风尘 2020-12-09 12:06

My application involves dealing with data (contained in a CSV) which is of the following form:

Epoch (number of seconds since Jan 1, 1970), Value
1368431149,         


        
3条回答
  •  误落风尘
    2020-12-09 12:44

    You can also use Pandas DatetimeIndex like so

    pd.DatetimeIndex(df['timestamp']*10**9)
    

    the *10**9 puts it into the format it's expecting for such timestamps.

    This is nice since it allows you to use functions such as .date() or .tz_localize() on the series.

提交回复
热议问题