I have a dataframe DF with 2 columns:
CLASS STUDENT
'Sci' 'Francy'
'Sci' Vacant
'math' 'Alex'
'math' 'Arthur'
'math' 'Katy'
'eng' 'Jack'
'eng' Vacant
'eng' 'Francy'
'Hist' 'Francy'
'Hist' 'Francy'
I need all the classes to have 1 vacant student. Some of them already have.
RESULT
CLASS STUDENT
'Sci' 'Francy'
'Sci' Vacant
'math' 'Alex'
'math' 'Arthur'
'math' 'Katy'
'math' Vacant
'eng' 'Jack'
'eng' Vacant
'eng' 'Francy'
'Hist' 'Francy'
'Hist' 'Francy'
'Hist' Vacant
I have tried
unique_class = DF['unique_class'].drop_duplicates()
vacant_column = pd.Series(['vacant'] * unique_class.shape[0])
temp_df = pd.concat([unique_class, vacant_column], axis=1, ignore_index=True)
DF = DF.append(temp_df, ignore_index=True)
DF.drop_duplicates(inplace=True)
It works but it seems too much. Any better way to do this?