Python 类型错误:';numpy.int64';对象不可编辑,显示为两列而不是1列

Python 类型错误:';numpy.int64';对象不可编辑,显示为两列而不是1列,python,numpy,dictionary,Python,Numpy,Dictionary,我试图用我的程序实现的是,通过使用pd读取csv文件。读取\u csv,然后尝试打印单个列,然后根据所选列构建词典。我正在使用gensim库制作字典 代码: import numpy as np import pandas as pd df = pd.read_csv('items.csv', sep='\t') from gensim import corpora, models, similarities corpus = df['id'] item_id = df.id print it

我试图用我的程序实现的是,通过使用
pd读取csv文件。读取\u csv
,然后尝试打印单个列,然后根据所选列构建词典。我正在使用
gensim
库制作字典

代码:

import numpy as np
import pandas as pd
df = pd.read_csv('items.csv', sep='\t')
from gensim import corpora, models, similarities
corpus = df['id']

item_id = df.id
print item_id
dictionary = corpora.Dictionary(corpus)
Traceback (most recent call last)
<ipython-input-23-4365f51dd2a7> in <module>()
      7 item_id = df.id
      8 print item_id
----> 9 dictionary = corpora.Dictionary(corpus)
     10 
     11 # review dictionary size

/usr/local/lib/python2.7/site-packages/gensim/corpora/dictionary.pyc in __init__(self, documents, prune_at)
     56 
     57         if documents is not None:
---> 58             self.add_documents(documents, prune_at=prune_at)
     59 
     60     def __getitem__(self, tokenid):

/usr/local/lib/python2.7/site-packages/gensim/corpora/dictionary.pyc in add_documents(self, documents, prune_at)
    117 
    118             # update Dictionary with the document
--> 119             self.doc2bow(document, allow_update=True)  # ignore the result, here we only care about updating token ids
    120 
    121         logger.info(

/usr/local/lib/python2.7/site-packages/gensim/corpora/dictionary.pyc in doc2bow(self, document, allow_update, return_missing)
    143         # Construct (word, frequency) mapping.
    144         counter = defaultdict(int)
--> 145         for w in document:
    146             counter[w if isinstance(w, unicode) else unicode(w, 'utf-8')] += 1
    147 

TypeError: 'numpy.int64' object is not iterable
通过以上代码,我得到了以下输出:

此错误:

import numpy as np
import pandas as pd
df = pd.read_csv('items.csv', sep='\t')
from gensim import corpora, models, similarities
corpus = df['id']

item_id = df.id
print item_id
dictionary = corpora.Dictionary(corpus)
Traceback (most recent call last)
<ipython-input-23-4365f51dd2a7> in <module>()
      7 item_id = df.id
      8 print item_id
----> 9 dictionary = corpora.Dictionary(corpus)
     10 
     11 # review dictionary size

/usr/local/lib/python2.7/site-packages/gensim/corpora/dictionary.pyc in __init__(self, documents, prune_at)
     56 
     57         if documents is not None:
---> 58             self.add_documents(documents, prune_at=prune_at)
     59 
     60     def __getitem__(self, tokenid):

/usr/local/lib/python2.7/site-packages/gensim/corpora/dictionary.pyc in add_documents(self, documents, prune_at)
    117 
    118             # update Dictionary with the document
--> 119             self.doc2bow(document, allow_update=True)  # ignore the result, here we only care about updating token ids
    120 
    121         logger.info(

/usr/local/lib/python2.7/site-packages/gensim/corpora/dictionary.pyc in doc2bow(self, document, allow_update, return_missing)
    143         # Construct (word, frequency) mapping.
    144         counter = defaultdict(int)
--> 145         for w in document:
    146             counter[w if isinstance(w, unicode) else unicode(w, 'utf-8')] += 1
    147 

TypeError: 'numpy.int64' object is not iterable
回溯(最近一次呼叫上次)
在()
7项目标识=df.id
8打印项目标识
---->9字典=语料库。字典(语料库)
10
11#查看字典大小
/usr/local/lib/python2.7/site-packages/gensim/corpora/dictionary.pyc in_u______________(self,documents,prune__at)
56
57如果文件不是无:
--->58 self.add_文档(文档,prune_at=prune_at)
59
60 def_uuugetItem_uuuu(self,tokenid):
/添加文档中的usr/local/lib/python2.7/site-packages/gensim/corpora/dictionary.pyc(self、documents、prune_at)
117
118#使用文档更新字典
-->119 self.doc2bow(document,allow_update=True)#忽略结果,这里我们只关心更新令牌ID
120
121.info(
/doc2bow中的usr/local/lib/python2.7/site-packages/gensim/corpora/dictionary.pyc(self、document、allow_update、return_missing)
143#构建(单词、频率)映射。
144计数器=defaultdict(int)
-->145对于文件中的w:
146计数器[w如果isinstance(w,unicode)或unicode(w,'utf-8')]+=1
147
TypeError:“numpy.int64”对象不可编辑
另一个问题这就是为什么我每次都得到两列而不是一列? 我对Python完全陌生。请在回答时考虑这个问题。

谢谢

“id头衔职业\级别纪律\ id行业\ id国家/地区经纬度就业标签在活动\测试期间创建”
“194298526”4316979“2643380318 15 Ch0 47.4 8.5 1 1471052”2072458 2512557 1077976 2643380137600 1780765 1156891 2809945 4298526 2849590 4316979 2338707 954599“366679 1438466400”
“116 822375 2 20 22 de 1 48.4 10.0 2 469901”3938421“3792911 14388120000”
“140 23232343”“3582227 3 12 15 at 0 47.3 11.1 2 3787103”“2360643 1444255200”
“161 2804344”1768488“1662103 3 15 21 de 0 48.1 16.9 1 281693”2788092 1185123 1768488 675557 1136325 1662103 4499767 3712454 3487119 3026440 751355 798840 3015937 4375914“624061 1436911201”
“190 3907924 3 14 15 de 6 53.6 10.0 1 4317479”4151211 38045“4425481 143881 2000 0”
“244 3772791”“1938824 3 15 11 de 10 51.2 7.1 1 1 3792911”1167575“1937646 1445814000 1”
“268 3582227 2 19 21 at 0 48.2 16.4 1 3792911”2971982 3668574“2359966 143768800 1”
“328 3836325”“2912912 3 12 15 de 10 50.9 6.9 1 2632767”2711443 4344735 2575161 751977 573207 1084525 799173 2076438 4252882 2245760 2603154 4151211 4498297 23183“732298 143852800”
“344 3 9 15 de 9 51.2 6.8 1 4432807”4152078 4421717“2850218 1439330400”
“350 2202904”“76751 3 20 14 de 5 53.1 8.8 1 155778”695299 3876540 1454092 4151211 798840 4329775 265439 3010695 177543“3129740 1436738400”
“380 3478136 3 15 8 de 9 52.2 8.5 1 1364799”2194612 3080025 4499767 234916“4151211 143483700”
“383 3586425”2608520 1919452 604369“3347280 4 19 2 de 2 50.1 11.3 1 289576”4173578 4324548 3586425 2969837 3726822 2231031“4499767 1437084000” “403 2573697”“1072229 3 13 11 de 7 50.1 8.2 1 2856334”4160943 649642 4011133 1272071 1072229 1643500“174682 1437084000”
“488 3267961”4305724“4432807 118 14 de 9 52.0 8.5 1 3872880”191860 675557 624061 1465860 3026440 4064526 3129740 1819239 234916“2683873 143768800”
“510 18903 3 15 ch 0 47.3 8.6 1 1339458”3792911 4501345 2085991 46678 910951 4263126 3972474 1604815 53586 1443376 3240672 2735573“3458589 1440453600 0”
“572 4063158 5 19 8 de 3 52.5 13.4 1 4432807”3596952 3626570 3937157 4384650 3347266“3938421 1432677600”
“573 1766375”“1506826 1 18 15 de 3 52.5 13.4 1 3287066”4323739 3600555 3466544 3487119 1443376 1272071 3087774 3472807 4228890“3726822 143768800”
“653 3 15 11 de 7 50.6 8.7 1 4432807”3487119 3843067 4011133 692505 213841 1571903“4321558 1437084000”

“693 4344735”4318371 2966139 1567907”2608520 3 16 11非达赫0 41.8-87.7 1 3176219“4328463 2026458 2846960 751977 24363 2632767 3407033 3498937 2224459 910951 33048 4344735 2735573 2076438889442 798840 127043726822 2231 1105913 1295675”251535空0

你能从csv中粘贴摘录吗?左列不就是行号吗?查看熊猫的显示标准。@FrancescoNazzaro,谢谢你的回答。我已经粘贴了问题中的一些行above@hpaulj,谢谢你的回复。左栏仅为行号。你能帮我翻译一下吗从您的csv中提取一个摘要?左列不是仅仅是行号吗?查看
pandas
display standards.@FrancescoNazzaro,谢谢您的回答。我在问题中粘贴了一些行above@hpaulj,谢谢您的回复。左栏仅为行号。