我有一个至少500行60列的大型数据框。我们称之为df1
。有些单元格中有NaN
,我通常使用
df2 = df1.fillna(value = 0.0)
以便仅用一行代码替换它们。
但是这是过去使用的非常小的数据帧,我希望将来在更大的数据量上执行相同的步骤。使用以上命令超出了我的递归限制。我还尝试增加递归限制,结果程序会崩溃。
我的初始递归限制是:
sys.getrecursionlimit()
1000
然后用
增加它sys.setrecursionlimit(10000)
并随后运行fillna()
会使我的程序崩溃。
为了解决递归问题,并使此命令迭代地工作,我创建了以下循环:
for index, row in sdd_root_excel.iterrows():
if(pd.isnull(row[index])):
sdd_root_excel.iloc[index].fillna(0)
但是我收到一条错误消息,我的解释似乎是在告诉我索引(为711?)超出范围,它也被解释为KeyError:
Traceback (most recent call last):
File "C:\Users\isabel.wingert\Anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 3103, in get_value
tz=getattr(series.dtype, 'tz', None))
File "pandas\_libs\index.pyx", line 106, in pandas._libs.index.IndexEngine.get_value
File "pandas\_libs\index.pyx", line 114, in pandas._libs.index.IndexEngine.get_value
File "pandas\_libs\index.pyx", line 162, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\hashtable_class_helper.pxi", line 1492, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas\_libs\hashtable_class_helper.pxi", line 1500, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 711
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "C:\Users\isabel.wingert\Anaconda3\lib\site-packages\pandas\core\series.py", line 766, in __getitem__
result = self.index.get_value(self, key)
File "C:\Users\isabel.wingert\Anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 3109, in get_value
return libindex.get_value_box(s, key)
File "pandas\_libs\index.pyx", line 55, in pandas._libs.index.get_value_box
File "pandas\_libs\index.pyx", line 70, in pandas._libs.index.get_value_box
IndexError: index out of bounds
我需要修复循环或尝试其他方法吗?