I have multiple pandas df that I'm trying to slice every column after a certain column (Target Col). The problem is Target Col will have a different index number each time I try to slice it. The Pandas dfs would look like this:
+------------+------+------+
| Target Col | Col2 | Col3 |
+------------+------+------+
| Data | Data | Data |
+------------+------+------+
+------+------------+------+
| Col1 | Target Col | Col3 |
+------+------------+------+
| Data | Data | Data |
+------+------------+------+
And what I want to pull is every column after the Target Col on each df:
+------------+------+
| Target Col | Col3 |
+------------+------+
| Data | Data |
+------------+------+
+------------+------+------+
| Target Col | Col2 | Col3 |
+------------+------+------+
| Data | Data | Data |
+------------+------+------+
What I have for code so far is (shortened for clarity):
for files in dir:
df = pd.read_excel(files)
target_cols = [col for col in df if col.startswith('Target Col')]
list_data = list(df.columns)
table_tail = df.iloc[:, list_data.index(target_cols[0]):]
The error I get is "ValueError: Must pass DataFrame with boolean values only"
The code is written that way (in and out of lists, a little convoluted) due to trying to write code to slice multiple Pandas dfs based on an index number. If someone has a shorter and less convoluted way to get this to work, I'm happy to hear some options.