Python Forum
Max recursion depth.... Error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Max recursion depth.... Error
#1
Hi All,

brand new to Python so appreciate the help. I am trying to add a new column, which should be calculated as the mean of 'math score' grouped by 'parental level of education' (attached is the spreadsheet), to an existing .csv file using the following code:

import pandas as pd


# file locations
input_file = "/Users/PYTHON/Exercise/StudentsGrades.csv"
output_file = "/Users/PYTHON/Exercise/"


df = pd.read_csv(input_file)
df.groupby(['parental level of education']).mean()
df['New Column'] = df.groupby
df.to_csv(output_file + 'File_w_Extra_Column.csv')
I keep getting this error: "RecursionError: maximum recursion depth exceeded in __instancecheck__".

I have googled the possible solution but haven't been able to make sense of it.

Appreciate your help!

Mel


.csv   StudentsGrades.csv (Size: 791 bytes / Downloads: 174)
Reply
#2
First, post code within Python tags (use the Python button) to keep the indentation and add highlighting, etc.

Second, please post the entire traceback verbatim - it contains information about where the error occurred.

Third, is that all the code? There doesn't appear to be any recursion. Having said that, why are you assigning df.groupby to your data frame? That seems.. odd to say the least.
Reply
#3
Like this?

I removed the line assigning df.groupby That was my attempt at adding the new calculated column into the output sheet...

Don't see the error occurring with the code below but there is no column added either.

thanks,
Mel

import pandas as pd



# file locations
input_file = "/Users/PYTHON/Exercise/StudentsGrades.csv"
output_file = "/Users/PYTHON/Exercise/"


df = pd.read_csv(input_file)
df.groupby(['parental level of education']).mean()
# df['New Column'] = df.groupby
df.to_csv(output_file + 'File_w_Extra_Column.csv')
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Bug maximum recursion depth exceeded while calling a Python object error in python3 Prezess 4 3,783 Aug-02-2020, 02:21 PM
Last Post: deanhystad
  why this error occured in recursion ashishraikwar 1 1,780 Apr-24-2020, 11:12 AM
Last Post: buran
  Lambda function recursion error DeadlySocks 1 2,076 Apr-13-2020, 05:09 PM
Last Post: deanhystad
  Requesting help with my implementation of depth-first search tigerfuchs 6 2,591 Sep-26-2019, 05:47 AM
Last Post: perfringo
  matplotlib recursion error when repeatedly displaying a surface AdeIsHere 0 1,938 Sep-19-2019, 04:36 PM
Last Post: AdeIsHere
  RecursionError: maximum recursion depth exceeded in comparison ? leoahum 11 13,092 Mar-18-2019, 01:53 PM
Last Post: leoahum
  variable loop depth Skaperen 5 4,348 Jul-18-2018, 02:48 AM
Last Post: Skaperen
  maximum recursion depth exceeded saba_keon 3 7,438 Apr-08-2018, 07:30 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020