Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中运行循环代码的系统时间时获取KeyError:859_Python_Pandas_Dataframe_Systemtime - Fatal编程技术网

在python中运行循环代码的系统时间时获取KeyError:859

在python中运行循环代码的系统时间时获取KeyError:859,python,pandas,dataframe,systemtime,Python,Pandas,Dataframe,Systemtime,这是密码 %%time xrange=range print ("Cleaning and parsing the tweets...\n") clean_tweet_texts = [] for i in xrange(nums[0],nums[1]): if( (i+1)%10000 == 0 ): print( "Tweets %d of %d has been processed" % ( i+1, nums[1] )) clean_twee

这是密码

%%time

xrange=range

print ("Cleaning and parsing the tweets...\n")

clean_tweet_texts = []

for i in xrange(nums[0],nums[1]):

    if( (i+1)%10000 == 0 ):

       print( "Tweets %d of %d has been processed" % ( i+1, nums[1] )) 

    clean_tweet_texts.append(tweet_cleaner(df_tweet['text'][i]))
以及错误总数消息:

Cleaning and parsing the tweets...


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<timed exec> in <module>()

~\Anaconda3\lib\site-packages\pandas\core\series.py in __getitem__(self, key)
    599         key = com._apply_if_callable(key, self)
    600         try:
--> 601             result = self.index.get_value(self, key)
    602 
    603             if not is_scalar(result):

~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_value(self, series, key)
   2475         try:
   2476             return self._engine.get_value(s, k,
-> 2477                                           tz=getattr(series.dtype, 'tz', None))
   2478         except KeyError as e1:
   2479             if len(self) > 0 and self.inferred_type in ['integer', 'boolean']:

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_value()

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_value()

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

KeyError: 859

无法破译此数据框。任何人都可以帮助解决此问题。此错误可能是由于多种原因造成的,但很可能是因为数据框的索引不包含您正在索引的数字,可能是您删除了该行。我能够用下面的代码得到完全相同的错误回溯

>>> df = pd.DataFrame(np.random.random((10,3)))
>>> df.drop(3,axis=0,inplace=True)
>>> for i in range(10):
...     print(df[0][i])
...
错误:

0.49022637034634586
0.5626132827030591
0.09118872448782767
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/home/dhananjay/.conda/lib/python3.7/site-packages/pandas/core/series.py", line 1071, in __getitem__
    result = self.index.get_value(self, key)
  File "/home/dhananjay/.conda/lib/python3.7/site-packages/pandas/core/indexes/base.py", line 4730, in get_value
    return self._engine.get_value(s, k, tz=getattr(series.dtype, "tz", None))
  File "pandas/_libs/index.pyx", line 80, in pandas._libs.index.IndexEngine.get_value
  File "pandas/_libs/index.pyx", line 88, in pandas._libs.index.IndexEngine.get_value
  File "pandas/_libs/index.pyx", line 131, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/hashtable_class_helper.pxi", line 992, in pandas._libs.hashtable.Int64HashTable.get_item
  File "pandas/_libs/hashtable_class_helper.pxi", line 998, in pandas._libs.hashtable.Int64HashTable.get_item
KeyError: 3

你们能分享数据的例子吗?哈罗·达南杰,谢谢,我得到了问题的答案,我的数组已经失效了