Suppose I have a DataFrame like this:
>>> df = pd.DataFrame([[1,2,3], [4,5,6], [7,8,9]], columns=['a','b','b'])
>>> df
   a  b  b
0  1  2  3
1  4  5  6
2  7  8  9
And I want to remove second 'b' column. If I just use del statement, it'll delete both 'b' columns:
>>> del df['b']
>>> df
   a
0  1
1  4
2  7
I can select column by index with .iloc[] and reassign DataFrame, but how can I delete only second 'b' column, for example by index?



bnot based of the column names as you have duplicates but indeed on an index. Thus your algorithm somehow uses that index. So why just not change the columns to an index based in that case?del df['b']translates to block manager command to remove relative items from all blocks, i.e. roughly equals to reassignmentdf = df.iloc[:,:2]