Removing rows after a certain string in pandas

Here is how I would tackle it:

ur_row = your_df.ix[your_df['Column_Name_Here']=='End of the 4th Quarter'].index.tolist()

ur_row is getting the index number of the row that meets the condition. Then we use slicing to get everythin up to that row. (The +1 is to capture the row including "End of 4th Quarter")

df.iloc[:ur_row[0]+1]

Hope this is simple to follow. I will gladly explain more if need be!


If you are sure there is always such a string somewhere in your data frame, you can use idxmax() to find out the corresponding index and then take all the rows before the index with loc:

df.loc[:(df == 'End of the 4th Quarter').any(1).idxmax()]

Here is a few lines at the end:

df.loc[:(df == 'End of the 4th Quarter').any(1).idxmax()].tail()

enter image description here