我正努力想抓住这个。我需要为每个评论创建一个pandas DataFrame对象,其中包含以下条目:
如果有人能帮我开始如何打印每一个产品/产品标识行,我将不胜感激。在
以下是我的文本文件示例:(很抱歉,当我在这个网站上输入时,我不知道如何正确格式化它)
product/productId: B001E4KFG0
review/userId: A3SGXH7AUHU8GW
review/profileName: delmartian
review/helpfulness: 1/1
review/score: 5.0
review/time: 1303862400
review/summary: Good Quality Dog Food
review/text: I have bought several of the Vitality canned dog food products and have found them all to be of good quality. The product looks more like a stew than a processed meat and it smells better. My Labrador is finicky and she appreciates this product better than most.
product/productId: B00813GRG4
review/userId: A1D87F6ZCVE5NK
review/profileName: dll pa
review/helpfulness: 0/0
review/score: 1.0
review/time: 1346976000
review/summary: Not as Advertised
review/text: Product arrived labeled as Jumbo Salted Peanuts...the peanuts were actually small sized unsalted. Not sure if this was an error or if the vendor intended to represent the product as "Jumbo".
product/productId: B000LQOCH0
review/userId: ABXLMWJIXXAIN
review/profileName: Natalia Corres "Natalia Corres"
review/helpfulness: 1/1
review/score: 4.0
review/time: 1219017600
review/summary: "Delight" says it all
review/text: This is a confection that has been around a few centuries. It is a light, pillowy citrus gelatin with nuts - in this case Filberts. And it is cut into tiny squares and then liberally coated with powdered sugar. And it is a tiny mouthful of heaven. Not too chewy, and very flavorful. I highly recommend this yummy treat. If you are familiar with the story of C.S. Lewis' "The Lion, The Witch, and The Wardrobe" - this is the treat that seduces Edmund into selling out his Brother and Sisters to the Witch.
这是一个开始,我无法破译您的几个字段/列,因此它可能需要更多的逻辑和文本消息处理。与其他答案类似:将文本解析到字典中键:值对-使用正则表达式查找对。在
如果我理解你的问题,我相信你想从一个结构与你写的文件。您可以使用以下代码创建一个数组,每个评论都是一个字典:
此代码将打印如下内容:
^{pr2}$您可以像这样访问每个对象:
然后你会得到这样的结果:
相关问题 更多 >
编程相关推荐