Reputation: 1
I'm fairly new to python.
I have been struggling with getting an excel formula to actually populate the formula in my spreadsheet. What I'm trying to do is in column1 if it contains the word dog, the corresponding column populates with blue and if column one contains the word cat that column2 populates with red.
Snippets from my code because it's stored elsewhere unless I need to rewrite it from top to bottom, just let me know.
I started off by creating a new column but I want to populate the row with a formula.
df.insert(2, 'Column2', "")
The actual Excel code I want to use =IF(ISNUMBER(SEARCH("dog", A2)), blue, IF(ISNUMBER(SEARCH("cat", H2)), red, "NOT FOUND")
I've tried worksheet.write_formula('B2', 'IF(ISNUMBER(SEARCH("dog", A2)), blue, IF(ISNUMBER(SEARCH("cat", H2)), red, "NOT FOUND"))
and df.append({"B2": 'IF(ISNUMBER(SEARCH("dog", A2)), blue, IF(ISNUMBER(SEARCH("cat", H2)), red, "NOT FOUND")}, ignore_index=True)
among others that I don't remember. I'm also trying to populate the whole column. Any insight would be very much appreciated. Everything I've tried so far either doesn't populate the cell or posts the code as a text.
Upvotes: 0
Views: 41
Reputation: 178
What is wrong with using Conditional Formatting?
In the words of Tom Scott (AKA an absolute legend) "Why code things that already exist?"
Upvotes: 0