Python Forum

Full Version: Max recursion depth.... Error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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

[attachment=1608]
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.
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')