so I have a dictionary with a bunch of keys and data frames
df_dict = {'grade_1_math': grade_1_class_2029,
'grade_2_eng': grade_2_class_2029,
'grade_3_math': grade_3_class_2029,
'grade_4_eng': grade_4_class_2029,
'grade_5_math': grade_5_class_2029}
every data frame has a string column called 'Course' that either will or won't have the word 'math' in it
I am trying to create a new column called 'Subject' which evaluates 'Course' and fills itself with either Mathematics or Language Arts
for key, val in df_dict.items():
val['Subject'] = np.where('math' in val['Course'], 'Language Arts', 'Mathematics')
but it comes out wrong every time. Am I doing something wrong? I would like to keep this in a dictionary loop since I do many other things as well.
@laurent asked for before and after of grade_1_class_2029.head().to_dict()
Before:
{'Course': {0: 'English 10',
1: 'English 10',
2: 'English 10',
3: 'English 10',
4: 'English 10'},
'Current Grade Level': {0: '12', 1: '12', 2: '12', 3: '11', 4: '12'},
'F1 Percent': {0: <NA>, 1: <NA>, 2: <NA>, 3: <NA>, 4: <NA>},
'Stored Grade Level': {0: '10', 1: '10', 2: '10', 3: '10', 4: '10'},
'Student_ID': {0: '20741', 1: '20722', 2: '20583', 3: '21111', 4: '20725'},
'Y1 Percent': {0: '81.2', 1: '83', 2: '79.5', 3: '59.6', 4: '88.3'}}
After:
{'Course': {0: 'English 10',
1: 'English 10',
2: 'English 10',
3: 'English 10',
4: 'English 10'},
'Current Grade Level': {0: '12', 1: '12', 2: '12', 3: '11', 4: '12'},
'F1 Percent': {0: <NA>, 1: <NA>, 2: <NA>, 3: <NA>, 4: <NA>},
'Stored Grade Level': {0: '10', 1: '10', 2: '10', 3: '10', 4: '10'},
'Student_ID': {0: '20741', 1: '20722', 2: '20583', 3: '21111', 4: '20725'},
'Subject': {0: 'Mathematics',
1: 'Mathematics',
2: 'Mathematics',
3: 'Mathematics',
4: 'Mathematics'},
'Y1 Percent': {0: '81.2', 1: '83', 2: '79.5', 3: '59.6', 4: '88.3'}}