R 将目录中的多个JSON文件读入一个数据帧
平行通过:R 将目录中的多个JSON文件读入一个数据帧,r,R,平行通过: {"Reviews": [{"Ratings": {"Service": "4", "Cleanliness": "5"}, "AuthorLocation": "Boston", "Title": "\u201cExcellent Hotel & Location\u201d", "Author": "gowharr32", "ReviewID": "UR126946257", "Content": "We enjoyed the Best Western Pioneer
{"Reviews": [{"Ratings": {"Service": "4", "Cleanliness": "5"}, "AuthorLocation": "Boston", "Title": "\u201cExcellent Hotel & Location\u201d", "Author": "gowharr32", "ReviewID": "UR126946257", "Content": "We enjoyed the Best Western Pioneer Square....", "Date": "March 29, 2012"}, {"Ratings": {"Overall": "5"},"AuthorLocation": "Chicago",....},{...},....}]}
库(并行)
cl对于来这里寻找purrr/tidyverse解决方案的任何人:
library(parallel)
cl <- makeCluster(detectCores() - 1)
json_files<-list.files(path ="your/json/path",pattern="*.json",full.names = TRUE)
json_list<-parLapply(cl,json_files,function(x) rjson::fromJSON(file=x,method = "R"))
stopCluster(cl)
库(purrr)
图书馆(tidyverse)
图书馆(jsonlite)
路径如果/当它返回时,您可以调用do.call(rbind,myJSON)
来获取单个data.frame,前提是data.frame是兼容的……一个JSON文件的示例将大大有助于人们帮助您purr::map_df
或purr::flatten_df
可能会有所帮助pbapply::pblappy
withdplyr::bind_rows
wld会给你一个进度条,如果你能从JSON获取以返回数据框
{"Reviews": [{"Ratings": {"Service": "4", "Cleanliness": "5"}, "AuthorLocation": "Boston", "Title": "\u201cExcellent Hotel & Location\u201d", "Author": "gowharr32", "ReviewID": "UR126946257", "Content": "We enjoyed the Best Western Pioneer Square....", "Date": "March 29, 2012"}, {"Ratings": {"Overall": "5"},"AuthorLocation": "Chicago",....},{...},....}]}
library(parallel)
cl <- makeCluster(detectCores() - 1)
json_files<-list.files(path ="your/json/path",pattern="*.json",full.names = TRUE)
json_list<-parLapply(cl,json_files,function(x) rjson::fromJSON(file=x,method = "R"))
stopCluster(cl)
library(purrr)
library(tidyverse)
library(jsonlite)
path <- "./your_path"
files <- dir(path, pattern = "*.json")
data <- files %>%
map_df(~fromJSON(file.path(path, .), flatten = TRUE))