Concatenating Boolean to DataFrames sqlQuery str

141 Views Asked by At

I am attempting to query the weather database for building decision trees. In it there are 14 instances and I am making new dataframes based on the intend subset that I want to query e.g -->

   new_data = data.query("'rainy' in Outlook")

will produce a new dataframe with 5 instances.

 ID                                    
 D    rainy  mild     high  False   yes
 E    rainy  cool   normal  False   yes
 F    rainy  cool   normal   True    no
 J    rainy  mild   normal  False   yes
 N    rainy  mild     high   True    no

To make my program more dynamic I am iterating through the datasets with parsed headers which look like this

    new_data = data.query("'rainy' in " + column_names[0])

Where column_names[0] is equal to Outlook. This is working fine , but the issue I am having is when I come to Windy which is a boolean. My question is how do I parse a boolean to a string to make a df query ? At the moment my code reads like this

      new_data = data.query("'" + False + "' in Windy")

but the error I am getting is TypeError: cannot concatenate 'str' and 'bool' objects I have tried many variations on the concatenation but have yet to find the correct format , if anyone else has experienced the same problem some insight would be much appreciated.

1

There are 1 best solutions below

3
On

Have you simply tried the following?

new_data = data.query("'" + str(False) + "' in Windy")