从CSV文件阅读器将值存储到字典中-ValueError

时间:2019-03-14 20:49:41

标签: python csv dictionary valueerror

我正在尝试读取csv并将其存储到字典中以进行进一步处理,但是我遇到了valueError。

aBody = {Id: aBody for Id, aBody in reader}
ValueError: not enough values to unpack (expected 2, got 1)

我的csv文件如下:

Id;aBody
100479;"<p>Here is good example:
<a href='http://www.codeproject.com/KB/dotnet/neuralnetwork.aspx'rel='noreferrer'>Brainnet 1 - A Neural Netwok Project - With Illustration And Code - Learn Neural Network Programming Step By Step And Develop a Simple Handwriting Detection System</a> that will demonstrate some practical uses of neural network programming.</p>"
1473317;"<p>Following on from dmckee's answer:</p>

<p>a x b = (a2b3 ? a3b2), (a3b1 ? a1b3), (a1b2 ? a2b1)</p>

<p>In your case a1=1, a2=0 a3=A  b1=0 b2=1 b3=B</p>

<p>so = (-A), (-B), (1)</p>"
1478163;"<p>Yes, devices like the Nintendo DS are plenty powerful enough for this sort of thing.  I haven't worked with the Nintendo DS specifically, but I have written a neural network character recognition app for a Windows Mobile smartphone, which is comparable in processing power.</p>

<p>As you mention, it all depends upon how you write it.  You could just as easily write something that <em>doesn't</em> work on the Nintendo DS.</p>"

我尝试过的代码如下:

with open('edited.csv', 'r') as aBody:
    reader = csv.reader(aBody)
    next(reader)
    aBody = {Id: aBody for Id, aBody in reader}

0 个答案:

没有答案