如何修复此错误"unhashable type: 'list"?



在下面CSV文件中的一个示例中,我希望通过考虑三个自变量来获得每个用户在每个屏幕上的所有时间;IpAddress"timeStamp";以及";screenName";。我得到了错误";不可更改的类型:"list";。

fn3 = 'screenviewclean.1.csv'
f2 = open(fn3,"r")
filereader = csv.reader(f2)
mhist = {}
i = 0
for line in filereader:
i+=1   
sec= line [10]
IpAddress = line [2]
timeStamp = line [6]
time = timeStamp[11:13]+ timeStamp[13:19]
Screen_View = line [7]
if i>1:
if IpAddress in mhist.keys():
mhist[IpAddress].append(Screen_View)
else:
mhist[IpAddress] = [Screen_View] 

#print (mhist)
chist = {}
for ip, screen in mhist.items():
k = screen
#print (k)
if k in chist.keys():
chist[k].append (time)
else:
chist[k] = [time]
print (chist)

这是我拥有的csv文件的示例:

Unnamed: 0  lastLoggedVersion   IpAddress   deviceId    deviceOS    userId  timeStamp   screenName  userType    doc.id  seconds
0   1.6.0.1 192.168.0.77    7612F62D-E392-4269-B49B-4F1214AA3888    iOS13.6.1   5U1XW8wkoqUPCTGhC1ni9Whinvt1    2020-11-13 22:28:55.029000+00:00    StudentProfile  student 00mrvPyS9Y2Al9iTN1vw    1231534.547
2   1.6.1.44    10.0.2.16   40a4dc7cb837fdec    Android10   27lFw6EnfbYFsU3F8AEejYGQRRl1    2020-11-12 21:28:00.998000+00:00    CompanySettings company 01dMOvAgsRTPSWXTDXIh    1141480.516
6   1.6.0.43    192.168.87.241  ec62706b2834bfcc    Android9    7XBtY5ZDxcPWYF7sGECDZxnH71b2    2020-11-12 21:41:33.126000+00:00    DiscoverCompanies   student 064kDvawK8cJoRl5if9d    1142292.644

您有for ip, screen in mhist.items()。但该字典中的值是屏幕列表,而不是单个屏幕。

你需要

for ip, screens in mhist.items():
for screen in screens:
....

相关内容

  • 没有找到相关文章

最新更新