如果我想使用DT2
从计算机中某个路径的dt1 <- data.table(col1 = paste0(rep(letters[1:26], times = 10000), rep(c(1:10000), each = 26)),
col2 = paste0(rep(letters[26:1], times = 10000), rep(c(1:10000), each = 26)),
col3 = rep(c(3,1,2,4,6,5,3,6,2,NA), times = 26000))
dt2 <- data.table(col1 = paste0(rep(letters[1:26], times = 10000), rep(c(1:10000), each = 26)),
col2 = paste0(rep(letters[26:1], times = 10000), rep(c(1:10000), each = 26)),
col3 = rep(c(10,NA,22,51,60,NA,32,NA,28,NA), times = 26000))
dt2alt <- copy(dt2)
microbenchmark::microbenchmark(
NoIfelse = dt2[is.na(col3), col3 := dt1[dt2[is.na(col3)], on = .(col1, col2), col3]],
Ifelse = dt2alt[dt1, on = .(col1, col2), col3 := ifelse(is.na(x.col3), i.col3, x.col3)]
)
#Unit: milliseconds
# expr min lq mean median uq max neval cld
# NoIfelse 94.06635 100.2841 107.4140 103.7807 107.4006 154.7868 100 a
# Ifelse 219.94923 243.2651 254.3271 250.6967 266.8300 306.7213 100 b
identical(dt2, dt2alt) #TRUE
文件中检索数据,我可以这样做:
xlsx
哪位给我zipfile
我可以打印。
如果我必须从URL检索文本,该怎么办? 我知道如何从中制作df(例如):
xml = zipfile.ZipFile(path).read('xl/sharedStrings.xml')
但是我需要一种类似于本地路径的解决方案,因为我还需要使用string
文件,
bs = urllib2.urlopen(url)
xd = pd.ExcelFile(bs)
df = xd.parse(0, header=None)
当然,欢迎其他解决方案从我未考虑的URL中从ods
获取字符串!预先感谢