I have a dataframe similar to this
import pandas as pd df = pd.DataFrame({'a': ['A', 'A'], 'b': ['B', 'D'], 'c': ['C', 'C'], 'd': ['D', 'D']}, index=[0, 1]) I would like to keep the right cell if the row has the same value
Desire Output
0 1 0 A 1 B D 2 C 3 D I have tried df = pd.DataFrame(list(map(pd.unique, df.values))) but it will push the values to the nearest left which is not my desired output.
Thank you for your help
https://stackoverflow.com/questions/67293129/keep-the-right-value-if-row-value-duplicates April 28, 2021 at 10:54AM
没有评论:
发表评论