| 1 | import pandas as pd |
| 2 | import numpy as np |
| 3 | import timeit |
| 4 | |
| 5 | np.random.seed(1) |
| 6 | |
| 7 | column_names_example = [i for i in range(10000)] |
| 8 | index = pd.MultiIndex.from_tuples( |
| 9 | [("left", c) for c in column_names_example] |
| 10 | + [("right", c) for c in column_names_example] |
| 11 | ) |
| 12 | df = pd.DataFrame(np.random.rand(1000, 20000), columns=index) |
| 13 | |
| 14 | |
| 15 | def keep_column(left_col, right_col): |
| 16 | return ( |
| 17 | left_col[left_col.first_valid_index()] > right_col[right_col.last_valid_index()] |
| 18 | ) |
| 19 | |
| 20 | |
| 21 | def do_it(): |
| 22 | v = [c for c in column_names_example if keep_column(df["left"][c], df["right"][c])] |
| 23 | return v |
| 24 | |
| 25 | |
| 26 | do_it() |