I have a dataframe with some duplicate index values with columns containing values for two different experiments. I want to prioritize Col_A if values are present across both index instances. I am working to solve this solution using the following algorithm.
- Merge rows with the same index
Pandas merging rows with the same value and same index
- Create new column with combine_first function. to select Col_A if present otherwise select Col_B
Example Data
data = {'id':['id3', 'id3', 'id6'],
'Col_A':[11,NaN,3],
'Col_B':[NaN,5,NaN]}
## Insert SO Magic Here
##
output = {'id':['id3', 'id6'],
'Col_Score':[11,3]}
If there is a "better" solution (shorter) than my proposed algorithm, please let me know.