我正在使用source_python
中的reticulate
函数将数据导入到我的R环境中。生成的嵌套列表看起来与R中本机创建的嵌套列表完全不同。如果有人可以帮助我将此列表转换为数据框,我将感到高兴。
您可以在此处参考其他信息,包括reticulate
上的类型转换:rstudio/reticulate
dput(my_list)
# list(list(A = 4658913, B = <environment>, C = "chr1", D = <environment>,
# E = <environment>, F = <environment>, G = FALSE, H = <environment>,
# I = <environment>, J = TRUE, K = "3958"), list(A = 78510,
# B = <environment>, C = "chr2", D = <environment>, E = <environment>,
# F = <environment>, G = TRUE, H = <environment>, I = <environment>,
# J = FALSE, K = "3620"))
class(my_list[[1]]$B)
# [1] "decimal.Decimal" "python.builtin.object"
str(my_list)
# List of 2
# $ :List of 11
# ..$ A: num 4658913
# ..$ B:7
# ..$ C: chr "chr1"
# ..$ D:254.9254204664572
# ..$ E:-36
# ..$ F:2549
# ..$ G: logi FALSE
# ..$ H:81
# ..$ I:0
# ..$ J: logi TRUE
# ..$ K: chr "3958"
# $ :List of 11
# ..$ A: num 78510
# ..$ B:20
# ..$ C: chr "chr2"
# ..$ D:823.4090235114015
# ..$ E:6359
# ..$ F:-5231
# ..$ G: logi TRUE
# ..$ H:229
# ..$ I:0
# ..$ J: logi FALSE
# ..$ K: chr "3620"
my_list[[1]]
# $A
# [1] 4658913
# $B
# 7
# $C
# [1] "chr1"
# $D
# 254.9254204664572
# $E
# -36
# $F
# 2549
# $G
# [1] FALSE
# $H
# 81
# $I
# 0
# $J
# [1] TRUE
# $K
# [1] "3958"