我有亚马逊的数据,想把它转换成csv格式的R或Python格式。我得到的原始数据如下:
product/productId: B000GKXY3
product/title: Nun Chuck
product/price: 17.99
review/userId: ADX8VLDUOL7BG
review/profileName: M. Gingras
product/productId: B000GKXY34
product/title: Nun Chuck
product/price: 17.99
review/userId: A3NM6P6BIWTIAE
review/profileName: Maria Carpenter
我想把它改成csv格式,如下所示:
^{pr2}$amazon数据集在我看来有点独特,不知道如何将其转换为csv格式。 我主要使用R,但也对Python开放。所以,任何知道如何使用R或Python实现这一点的人,请分享您的想法。在
提前谢谢。在
我假设,你拥有固定的字段列表。在这种情况下,您可以这样生成csv:
假设你的数据和你的样本是一致的:有序的,5行,第6行是空的。。。在
结果:
^{pr2}$这里有一种在R中实现的方法,它要求所有数据块的字段(顺序和名称)都是相同的,并且数据块用空行分隔。我想有更简单的方法来实现这一点,也许使用
plyr
?在读入一些数据。您可以将
readLines
指向文本文件。在然后你可以很容易地强制使用一个
data.frame
来使product/price
数字,如果这能让你的船漂浮。在相关问题 更多 >
编程相关推荐