I have a DataFrame with an index called SubjectID
and a column Visit
. Subjects have multiple Visits and either an integer value or an N/A for
You can use groupby.first or groupby.last to get the first/last non-null value for each column within the group. For the example data, the output would be the same for either method:
df = df.groupby(['SubjectID', 'Visit']).first().reset_index()
The resulting output:
SubjectID Visit Value1 Value2
0 B1 1 1.57 1.75
1 B1 2 NaN 1.56