我有從 R 中的 CSV 匯入的資料。DateTime 采用 excel 格式(即 44410.095193、44410.095203 等)。
這是我的一小部分資料的復制品:
> dput(tail(raw.data[,1]))
structure(list(DateTime = c(44410.095193, 44410.095203, 44410.095215,
44410.095227, 44410.095238, NA)), row.names = c(NA, -6L), class = c("data.table",
"data.frame"), .internal.selfref = <pointer: 0x000002048fb61ef0>)
我發現有幾種簡單的方法可以通過使用XLDateToPOSIXctfromDescTools打包并在桌面版 R 上convertToDateTime形成openxlsx包。
但是,這些功能在 R 的 Jupyter Notebook 版本中不起作用。我嘗試在 Jupyter Notebook 中安裝上面列出的軟體包,但之后我總是收到一條錯誤訊息:
#for the openxlsx package
Error in convertToDateTime(raw.data$DateTime): could not find function "convertToDateTime"
Traceback:
#for the DescTools package
Error in XLDateToPOSIXct(raw.data$DateTime): could not find function "XLDateToPOSIXct"
Traceback:
我認為必須有另一種方法來進行轉換。我已經嘗試過as.Date和as.POSIXct功能,但這些并沒有給我我需要的所有資料(只是日期而不是時間)或者是不正確的(所有年份都是 1899 年)。
哪些函式可以在 Jupyter Notebook 中作業,將 DateTime 的數字版本轉換為實際日期/時間(例如,2021-08-02 02:17:05)?
uj5u.com熱心網友回復:
應該在您的筆記本中使用的基本 R解決方案。第二個as.POSIXct啟用時間部分。確保您的 data.frame 日期是numeric.
dat <- c(44410.095193, 44410.095203, 44410.095215, 44410.095227, 44410.095238, NA)
class(dat)
[1] "numeric"
as.POSIXct( as.Date( dat, origin="1899-12-30" ) )
[1] "2021-08-02 04:17:04 CEST" "2021-08-02 04:17:05 CEST"
[3] "2021-08-02 04:17:06 CEST" "2021-08-02 04:17:07 CEST"
[5] "2021-08-02 04:17:08 CEST" NA
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/370516.html
標籤:r 约会时间 jupyter-笔记本
