Suppose I have a DataFrame:
>>> df = pd.DataFrame([[1,2,3], [4,5,6], [7,8,9]], columns=['a','b','b']) >>> df abb 0 1 2 3 1 4 5 6 2 7 8 9
And I want to remove the second column 'b' . If I just use the del operator, it will remove the 'b' columns:
>>> del df['b'] >>> df a 0 1 1 4 2 7
I can select the column by index with .iloc[] and reassign the DataFrame, but how to remove only the second column 'b' , for example, by index?
python pandas
Roman pekar
source share