I've created a dataframe:
In [1]: import pandas as pd
In [2]: import numpy as np
In [3]: df = pd.DataFrame({ 'Student_ID':['001','002','003','004','005'],
'Amy' : ['Amy',np.nan,np.nan,np.nan,'Amy'],
'Brian' : [np.nan,'Brian',np.nan,np.nan,np.nan],
'Cat' : [np.nan,np.nan,np.nan,'Cat',np.nan]},columns=['Student_ID','Amy','Brian','Cat'])
In [4]:df
Out [4]:
Student_ID Amy Brian Cat
0 001 Amy NaN NaN
1 002 NaN Brian NaN
2 003 NaN NaN NaN
3 004 NaN NaN Cat
4 005 Amy NaN NaN
And next I'd like to return to a dataframe with two columns only, Student_ID and Name. How to convert to below in precise codes?
In [5]: df
Out[5]:
Student_ID Name
0 001 Amy
1 002 Brian
2 003 NaN
3 004 Cat
4 005 Amy