Reputation: 261
With a data frame, I want to drop all rows where the first columns contains the string or substring 'XYZ'. I know this works:
df[~df.NameOfColumn.str.contains("XYZ")]
However, I do not want to use the name of the first column. (This is because I have lots of dataframes and the names of their first column is different). Any idea how to do that?
Upvotes: 1
Views: 102
Reputation: 862751
Use DataFrame.iloc
for select first column by position 0
, here :
means select all rows:
df[~df.iloc[:, 0].str.contains("XYZ")]
Upvotes: 1