Python:将纳秒转换为DateTime64格式

Plu*_*ug4 4 python numpy pandas

我有一个timestamps在几秒钟内(从午夜开始)的列,具有纳秒级精度34200.934549345, 34205.735545344,在DataFrame中等等df.

这些timestamps来自同一天2011-01-10.

如何以纳秒精度转换这些秒的DateTime64格式为numpy

我想在我的这些条目 df

2011-01-10 9:30:00.934549345
2011-01-10 9:30:05.735545344
Run Code Online (Sandbox Code Playgroud)

我需要在问题的解决方案下执行类似于此示例中的确切操作.

可能吗?

U2E*_*EF1 5

> df = pd.DataFrame({'seconds_since_midnight': [34200.934549345, 34205.735545344]})
> df['actual_date'] = (df.seconds_since_midnight * 1e9).astype('timedelta64[ns]') + pd.to_datetime('2011-01-10')
> df
   seconds_since_midnight                   actual_date
0            34200.934549 2011-01-10 09:30:00.934549345
1            34205.735545 2011-01-10 09:30:05.735545344

[2 rows x 2 columns]
Run Code Online (Sandbox Code Playgroud)