简体   繁体   English

在处理上述异常期间,发生了另一个异常

[英]During handling of the above exception, another exception occured

so basically what I'm trying to do is read a column from a csv file to an array then do calculations with that array. 所以基本上我想做的是从csv文件中读取一列到数组,然后对该数组进行计算。 I have successfully gotten the array 'rawSunlightData' from the csv file but for some reason every time I try to select a variable from 'raySunlightData' array I get the error [During handling of the above exception, another exception occured] I can print the whole rawSunlightData but can't print individual values like rawSunlightData[0] 我已经从csv文件中成功获取了数组'rawSunlightData',但是由于某种原因,每次我尝试从'raySunlightData'数组中选择一个变量时,都会出现错误[在处理上述异常期间,发生了另一个异常]我可以打印整个rawSunlightData,但无法打印单个值,例如rawSunlightData [0]

    cleanSunlightData = []
    rawSunlightData = pd.read_csv('Average daily sunlight per month.csv', header = None)
    rawSunlightData = rawSunlightData.drop(rawSunlightData.columns[[0]], axis=1)
    print(rawSunlightData[0])
    i = 0
    while i <= len(rawSunlightData):

        arrayDivider = []

        m = 0
        while m < 12:
            x = i + m
            print(x)
            m += 1

        i += 12

the error message is 错误消息是

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/indexes/base.py", line 3078, in get_loc
 return self._engine.get_loc(key)
 File "pandas/_libs/index.pyx", line 140, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/index.pyx", line 162, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/hashtable_class_helper.pxi", line 958, in pandas._libs.hashtable.Int64HashTable.get_item
File "pandas/_libs/hashtable_class_helper.pxi", line 964, in pandas._libs.hashtable.Int64HashTable.get_item
KeyError: 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
 File "/Users/kennethwong/Desktop/Singapore crop yield /Downloaded data/Data cleaner.py", line 67, in <module>
cleanSunlightData()
File "/Users/kennethwong/Desktop/Singapore crop yield /Downloaded data/Data cleaner.py", line 46, in cleanSunlightData
 print(rawSunlightData[0])
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/frame.py", line 2688, in __getitem__
return self._getitem_column(key)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/frame.py", line 2695, in _getitem_column
return self._get_item_cache(key)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/generic.py", line 2489, in _get_item_cache
values = self._data.get(item)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/internals.py", line 4115, in get
loc = self.items.get_loc(item)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/indexes/base.py", line 3080, in get_loc
return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas/_libs/index.pyx", line 140, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/index.pyx", line 162, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/hashtable_class_helper.pxi", line 958, in pandas._libs.hashtable.Int64HashTable.get_item
  File "pandas/_libs/hashtable_class_helper.pxi", line 964, in pandas._libs.hashtable.Int64HashTable.get_item
KeyError: 0

样本数据

its okay guy I found out why, im still new to coding so I make mistakes... when you pull data from csv file and store it in a data frame, it is NOT an array ! 没关系,我发现了原因,我还是编码的新手,所以我会犯错误...当您从csv文件中提取数据并将其存储在数据帧中时,它不是数组! you will have to convert it to an array by array.to_records() 您将必须通过array.to_records()将其转换为数组

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在处理上述异常的过程中,又发生了一个异常 - During handling of the above exception, another exception occurred 在处理上述异常期间,发生了另一个异常:Python程序 - During handling of the above exception, another exception occurred: Python program KeyError: 1 在处理上述异常的过程中,又发生了一个异常: - KeyError: 1 During handling of the above exception, another exception occurred: Flask-restful - 在处理上述异常的过程中,发生了另一个异常 - Flask-restful - During handling of the above exception, another exception occurred 关键错误:1 在处理上述异常的过程中,发生了另一个异常 - Key Error: 1 During handling of the above exception, another exception occurred KeyError:在处理上述异常的过程中,发生了另一个异常 - KeyError: During handling of the above exception, another exception occurred 在处理上述异常的过程中,发生了另一个异常:'Date' - During handling of the above exception, another exception occurred: 'Date' 在处理上述异常的过程中,又发生了一个异常:&amp; google sheet not found - During handling of the above exception, another exception occurred: & google sheets not found “在处理上述异常过程中,发生了另一个异常”for循环中的第一个输入 - “ during the handling of above exception, another exception occurred ” for the first input in the for loop 如何解决“在处理上述异常期间,发生了另一个异常:” - How to fix "During handling of the above exception, another exception occurred: "
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM