假设我有以下Excel文件:
111
333444
尝试:
#index of first row above "start"
row_index = df[df.shift(-1).eq("start").any(axis=1)].index.min()
#name of first column before the column that contains "start"
col_index = df.loc[:,df.shift(-1, axis=1).eq("start").any(0)].columns[0]
#select all rows and columns per the above indices.
>>> df.loc[row_index:, col_index:]
B C
0 11 111
1 22 start
2 33 333
3 44 444