0

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.

Steve
  • 4,388
  • 3
  • 17
  • 25

1 Answers1

0

Have you simply tried the following?

new_data = data.query("'" + str(False) + "' in Windy")
siphr
  • 421
  • 4
  • 12
  • I hadn't , but it wont work because then you are making a comparison between a boolean and a string and it will designate them incompatible. It would avoid the compiling error though , just not solve the problem :) – Steve Feb 29 '16 at 18:55
  • @Steve can you check it as an integer? 1/0 = True/False? – siphr Feb 29 '16 at 18:58
  • Afraid not , as soon as you parse the integer to the query string it becomes just a string and prefixing it with a case bool(1) only throws up the initial compiling error. – Steve Feb 29 '16 at 19:06