我有如下的数据样本。它非常大,我想从中抽取前10件。它看起来像是一个dict列表,但是如果我尝试user_train[:5],就会得到一个错误。我可以像用户培训[4]一样一次抽取一个项目。任何提示都非常感谢。
代码:
user_train[0]
输出:
[{u'asin': u'B00APT3MHO',
u'helpful': [0, 0],
u'overall': 5.0,
'productid': 1,
u'reviewText': u"Good for someone who likes skinny jeans but doesn't look great in the legging-tight ones. A little stretchy. Not super tight in the knee or ankle, but snug on the thigh and calf.",
u'reviewTime': u'11 17, 2013',
u'reviewerID': u'A1JWX45KHE34AL',
u'reviewerName': u'varnienarsil',
u'summary': u'Love these jeans',
u'unixReviewTime': 1384646400},
{u'asin': u'B00CJ5NH36',
u'helpful': [0, 0],
u'overall': 5.0,
'productid': 2,
u'reviewText': u"This shirt with it's bold graphic is seriously adorable. I have pretty narrow shoulders, and like the way the sleeves slope off them. The shirt fits loosely in a way that is flattering and I liked the length. I'm no model, but the shirt looks on me as great as it looks in the photo.",
u'reviewTime': u'11 17, 2013',
u'reviewerID': u'A1JWX45KHE34AL',
u'reviewerName': u'varnienarsil',
u'summary': u'As cute as it looks',
u'unixReviewTime': 1384646400},
{u'asin': u'B00F9NGAPM',
u'helpful': [1, 1],
u'overall': 3.0,
'productid': 4,
u'reviewText': u"The shirt is a little flowy-er than I expected. I like the way it drapes, but the arms are a bit loose (and on me, short—I'm pretty tall). Has a sort of after-yoga feel rather than the urban feel I was looking for. Super comfortable.",
u'reviewTime': u'11 17, 2013',
u'reviewerID': u'A1JWX45KHE34AL',
u'reviewerName': u'varnienarsil',
u'summary': u"Like, don't love",
u'unixReviewTime': 1384646400}]
Update:
code:
user_train[:5]
error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-17-bb27c2e9fa75> in <module>()
----> 1 user_train[:5]
TypeError: unhashable type