Consider following dataframe which has columns with same name (Apparently this does happens, currently I have a dataset like this! :( )
>>> df = pd.DataFrame({"a":range(10,15),"b":range(5,10)}) >>> df.rename(columns={"b":"a"},inplace=True) df a a 0 10 5 1 11 6 2 12 7 3 13 8 4 14 9 >>> df.columns Index(['a', 'a'], dtype='object') I would expect that when dropping by index , only the column with the respective index would be gone, but apparently this is not the case.
>>> df.drop(df.columns[-1],1) 0 1 2 3 4 Is there a way to get rid of columns with duplicated column names?
EDIT: I choose missleading values for the first column, fixed now
EDIT2: the expected outcome is
a 0 10 1 11 2 12 3 13 4 14
df.drop("a",1). I wanted to bypass this by using integer column indices, but it had same effect asdf.drop("a",1)