I am just starting with python and pandas. I have a dataframe that looks like this:
1 2.3 1 2.5 1 4.52 2.3 2 2.5 2 4.53 2.3 3 2.5 3 4.54 2.3 4 2.5 4 4.55 2.3 5 2.5 5 4.5I am trying to remove all the identical columns except for the first one so I want to be left with:
1 2.3 1 2.5 1 4.52 2.3 2 2.5 2 4.53 2.3 3 2.5 3 4.54 2.3 4 2.5 4 4.55 2.3 5 2.5 5 4.5I have managed to obtain the indices of the identical columns in a list duplicate_cols.`duplicate_cols=[2,4] in the example above.
But when I try to extract them from the dataframe with:
dataframe.drop(dataframe.columns[duplicate_cols], axis=1)All the columns are removed (the ones with 1 2 3 4 5 I mean). I was expecting the first column to stay.
Can anyone tell me where I am doing something wrong?