简体   繁体   English

R - 将大型数据框导出为 CSV

[英]R - Export large dataframe into CSV

Beginner here: I have a list (see screenshot) called Coins_list from which I want to export the second dataframe stored in it called data into a csv.初学者:我有一个名为Coins_list的列表(见屏幕截图),我想从中将存储在其中的第二个data帧导出为 csv。 When I use the code当我使用代码时

write.csv(Coins_list$data, file = "Coins_list_full_data.csv")

I get a huge CSV with a bunch of numbers from the column named price which apparently containts more dataframes, if I read the output correctly or at least display the data in the price column?如果我正确读取输出或至少在价格列中显示数据,我会从名为price的列中获得一个包含大量数字的巨大 CSV,该列显然包含更多数据框? How can I export this dataframe into CSV correctly?如何正确将此数据框导出为 CSV? See screenshot for more details.有关更多详细信息,请参阅屏幕截图。 截屏

EDIT: I was able to get the first four rows into CSV by using df2 <- Coins_list$data write.csv(df2[1:4,], file="BTC_row.csv") , however it now looks like R puts the price of all four rows within a list c( ) and repeats it in each row?编辑:我能够使用df2 <- Coins_list$data write.csv(df2[1:4,], file="BTC_row.csv")将前四行转换为 CSV,但是现在看起来 R 将列表 c( ) 中所有四行的价格并在每一行中重复? Any idea how to change that?知道如何改变吗?

在此处输入图像描述

(I would post this as a comment but I have too few reputation) (我会将此作为评论发布,但我的声誉太少)

Hey, you could try for starters to flatten the json file by going further than response list$content but looking at what's into the content with another $.嘿,您可以尝试让初学者通过比响应 list$content 更进一步来扁平化 json 文件,但用另一个 $. 查看内容中的内容。

Else you could try getting data$price and see what pops up from there.否则,您可以尝试获取 data$price 并查看从那里弹出的内容。

something like this:像这样的东西:

names = list(data$symbol)

df = data.frame(price = NA, symbol = NA)

for (i in length(data)) {
  
  
  x = data.frame(price = data$price[i], symbol = names[i])
  
  df = inner_join(df, data)
  
  
}

to get a dataframe with price and symbol.获取带有价格和符号的数据框。 I don't know how the data is nested so I'm just guessing.我不知道数据是如何嵌套的,所以我只是猜测。

It would be helpful to know from where you got the data for reproducibility.了解您从哪里获得可重复性数据会很有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM