Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing columns containing duplicated data from a pandas dataframe? [duplicate]

If I have a dataframe like below:

|  Column A  |  Column B  |  Column C  |  Column D  |  Column E  |
|:-----------|:---------- |:-----------|:-----------|:-----------|
| 1          | 7          | 1          | 13         | 13         |
| 2          | 8          | 2          | 14         | 13         |
| 3          | 9          | 3          | 15         | 13         |
| 4          | 10         | 4          | 16         | 13         |
| NA         | 11         | NA         | 17         | 13         |
| 6          | 12         | 6          | 1          | 13         |

I'd like to remove the duplicate columns A (or C), ignoring the fact that Column E has duplicate rows, and ignoring the column headers.

like image 389
CaesiumWhale Avatar asked Dec 01 '22 14:12

CaesiumWhale


1 Answers

You can transpose and then transpose back:

df.T.drop_duplicates().T
like image 113
gold_cy Avatar answered Dec 04 '22 03:12

gold_cy