Search code examples
pythonpandasconditional-statementstext-mining

If a condition is true how to extract specific rows addressing that condition from a csv file as print result


If I have 2 conditions: 1. a document is health relate 2. a document is not health-related and my document satisfies one of the above-mentioned conditions. As an output, it must pull out data from a CSV file from rows associated with this condition say row 1, 5, and 8, and print it.


Solution

  • import pandas as pd
    
    df = pd.read_csv('path/to/csv')
    
    print(df.iloc[1, 5, 8])