Search code examples
pythonpandasdataframelogic

How to store the row value of a logic statement in python df


What I am trying to do is add a search feature into a dataframe. I want to be able to type a file name and save the row it was found true. That way when I use iloc it will return the "filename" and "modified_data" together.

import pandas as pd
#....
df = pd.DataFrame(data, columns=['filename', 'modified_date'])
if df['filename'].str.contains('AAROW PDM Report') == TRUE:
    RowValue = #I want it to be equal to the row that was found true

print(df.iloc[[RowValue]])

Solution

  • Try:

    RowValue = df['filename'].str.contains('AAROW PDM Report').idxmax()