0

There is a way to filter in a df column only the rows with a especific word inside the text, like function 'str.contains' just using the .query function ?

This is the code i have:

def filter(self):

    build_query = ""
    
    if self.lineEdit_name.Text():
        build_query += f'& "{self.lineEdit_name.Text()}" in `name`'
    if self.lineEdit_description.Text():
        build_query += f'& "{self.lineEdit_description.Text()}" in `desc`'
    if self.comboBox_section.currentText():
        build_query += f'& "{self.comboBox_section.currentText()}" in `section`'

    if build_query:
        self.queried_df = self.df.query(build_query[1:])
    else:
        self.queried_df = self.df

I wanted to search in the description column for keywords.

Silvio Duarte
  • 41
  • 1
  • 5
  • 2
    You can call `str.contains` inside a `query` call, for example. `df.query("col.str.contains('some_text')")`. [This post](https://stackoverflow.com/a/73762002/19123103), especially #3 may be helpful. – cottontail Jan 10 '23 at 04:21

0 Answers0