我有如下样本的数据。它非常大,我想从它的前10个样品。它看起来像是一个dict列表,但是如果我尝试user\u 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
如果你想找到解决办法的话。你可以去:
sample = [user_train[x] for x in range(10)]
这称为列表理解,不可修复的类型错误通常是由于试图将dict转换为列表
相关问题 更多 >
编程相关推荐