Pivot table with duplicate rows and column-Drop

Viewed 25

Having a pivot table as below. having a variable my_var='A'. I need to drop only one A from the pivot table. Is that possible?

IMG

Expected Output:

img2

1 Answers

Due the fact that the columns have duplicated names, the same goes for the index. The drop function would delete both As.

The easiest way to get the result you want is using .iloc, or you change the column names.

dfSOF = pd.DataFrame(columns=['A','A','B'], index=['A','A','B'], data=[[0,0,4],[0,0,4],[6,6,0]])
dfSOF = dfSOF.iloc[1:, 1:]
Related