Search code examples
pythonpython-3.xpandasrowpandas-datareader

How to select rows in Pandas


I have a csv like:

1. [Book; Value]

2.[Expenses_b; 500]

3. [Expenses; 1000]

4. [Cash; 900]

I need to select the rows that match with book = Expenses and Expenses_b. I can select them separately, as the example:

import pandas as pd

data = pd.read_csv(r'path', sep='\t')
Expenses = data[data.Book == 'Expenses' ]

Is that any way I can select both of them together or rows that contain 'Expenses'?


Solution

  • Simply by using str method on the given series.

    expenses = data[data.Book.str.contains("Expenses")]