[英]R: Reading first n rows from parquet file?
感谢 Jon 和 Dan 指出了正确的方向。
arrow::open_dataset()
允许延迟评估(文档 [此处][1]),然后您可以从中获取head()
(但不能slice()
)或filter()
。 这个过程更快,并且使用更少的峰值内存。 下面的例子。
# https://stackoverflow.com/questions/73131505/r-reading-first-n-rows-from-parquet-file
library(dplyr)
library(arrow)
library(tictoc) #optional, used to time results
tic("read all of large parquet file")
my_animals <- read_parquet("data/my_animals.parquet")
toc() # slow and uses heaps of ram
tic("read parquet and write mini version")
my_animals <- open_dataset("data/my_animals.parquet")
my_animals # this is a lazy object
my_animals %>%
#slice(1000L) %>% #doesn't work
head(n=1000L) %>%
# filter(YEAROFBIRTH >= 2010) %>% #also works
compute() %>%
write_parquet("data/my_animals_mini.parquet") # optional
toc() # much faster, much less peak ram used
[1]: https://arrow.apache.org/docs/r/articles/dataset.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.