Suppose one has a dataframe created as such:
tdata = {('A', 50): [1, 2, 3, 4],
('A', 55): [5, 6, 7, 8],
('B', 10): [10, 20, 30, 40],
('B', 20): [50, 60, 70, 80],
('B', 50): [2, 4, 6, 8],
('B', 55): [10, 12, 14, 16]}
tdf = pd.DataFrame(tdata, index=range(0,4))
A B
50 55 10 20 50 55
0 1 5 10 50 2 10
1 2 6 20 60 4 12
2 3 7 30 70 6 14
3 4 8 40 80 8 16
- How would one drop specific columns, say ('B', 10) and ('B', 20) from the dataframe?
- Is there a way to drop the columns in one command such as
tdf.drop(['B', [10,20]])? Note, I know that my example of the command is by no means close to what it should be, but I hope that it gets the gist across. - Is there a way to drop the columns through some logical expression? For example, say I want to drop columns having the sublevel indices less than 50 (again, the 10, 20 columns). Can I do some general command that would encompass column 'A', even though the 10,20 sublevel indices don't exist or must I specifically reference column 'B'?
Can I do some general command that would encompass column 'A', even though the 10,20 sublevel indices don't exist or must I specifically reference column 'B'?