我有下面给出的json文件。我想将其转换为数据框。
json_file-> [{'a': "abc", "date": "20190506", "my_col":{"weather":10, "ice": 12}},
{'a': "xyz", "date": "20190507", "my_col":{"summer":18, "hot": 14}}]
数据框应如下所示:
a date mycol
abc 20190506 "weather":10, "ice": 12
xyz 20190507 "summer":18, "hot": 14
尝试:
json_file <- fromJSON(json_file)
json_file <- lapply(json_file, function(x) {
x[sapply(x, is.null)] <- NA
unlist(x)
})
答案 0 :(得分:0)
使用rjson
fromJSON
library(rjson)
l='[{"a": "abc", "date": "20190506", "my_col":{"weather":10, "ice": 12}},{"a": "xyz", "date": "20190507", "my_col":{"summer":18, "hot": 14}}]'
l = fromJSON(l)
do.call(rbind, l)
a date my_col
[1,] "abc" "20190506" List,2
[2,] "xyz" "20190507" List,2