0

I need help on how to deal with the recursion depth error. I am getting this error when I try to replace NaN values with the median (due to outliers in a single column), using the below mentioned code,

app_data['AMT_REQ_CREDIT_BUREAU_YEAR'].fillna(app_data['AMT_REQ_CREDIT_BUREAU_YEAR'].median, inplace = True)
  • The shape of the data is (307511, 18)
  • The missing values in the column AMT_REQ_CREDIT_BUREAU_YEAR are 41519

How do I fix the error I'm getting? RecursionError: maximum recursion depth exceeded

Pratham_Amitabh
  • 61
  • 2
  • 11

2 Answers2

1

median() is a function. You passed a function, not a function result as you issed the ()

app_data = pd.DataFrame({"DATE":d, 
                         "AMT_REQ_CREDIT_BUREAU_YEAR":
                         [i.year if random.randint(0,3)<2 else np.nan for i in d]})

fillval = app_data['AMT_REQ_CREDIT_BUREAU_YEAR'].median()
app_data['AMT_REQ_CREDIT_BUREAU_YEAR'].fillna(app_data['AMT_REQ_CREDIT_BUREAU_YEAR'].median(), inplace = True)
app_data
Rob Raymond
  • 29,118
  • 3
  • 14
  • 30
0

Hope this helps somebody else -

I faced the same error while deep copying a FileObject in Flask:

file_blob = copy.deepcopy(file_object)

Which threw the error:

RecursionError: maximum recursion depth exceeded

Solution: Based on this answer, add the below line at the top of your script:

sys.setrecursionlimit(1500)