I think that you can do this with stack
, drop_duplicates
and unstack
:
data.set_index(['A','B']).stack().drop_duplicates().unstack().reset_index()
A B C D
0 0 50 a y
1 10 22 b c
2 11 35 r w
3 21 5 x z
More Related Contents:
- How to write this code without using pandas?
- How to plot in multiple subplots
- Faster way to read Excel files to pandas dataframe
- Format y axis as percent
- float64 with pandas to_csv
- How do I transpose dataframe in pandas without index?
- How to select all columns whose names start with X in a pandas DataFrame
- Append column to pandas dataframe
- How do I round datetime column to nearest quarter hour
- How to plot and annotate grouped bars in seaborn / matplotlib
- Print the raw value of a column alone, in pandas?
- Pandas merge two dataframes with different columns
- Pandas filter dataframe rows with a specific year
- Divide multiple columns by another column in pandas
- Access index in pandas.Series.apply
- Python Pandas to_sql, how to create a table with a primary key?
- Pandas “Group By” Query on Large Data in HDFStore?
- Apply function to each cell in DataFrame
- Export Pandas DataFrame into a PDF file using Python
- Concat DataFrame Reindexing only valid with uniquely valued Index objects
- pandas – Merge nearly duplicate rows based on column value
- Pivot Tables or Group By for Pandas?
- Giving a column multiple indexes/headers
- Create a pandas DataFrame from generator?
- Pandas DataFrame search is linear time or constant time?
- case_when function from R to Python
- Pandas Dataframe Comparison and Floating Point Precision
- numerical sort a column containing numbers and strings (pandas/python)
- Faster way to transform group with mean value in Pandas
- DataFrame object has no attribute append