I have been trying to use variables for passing the string value in dataframe for various column operations, but the code is giving me wrong results. See the code below, I am using in Jupyter Notebook:
first_key = input("key 1: ")
second_key = input("ket 2: ")
third_key = input("ket 2: ")
These receive the values "Russia", "China", "Trump" for the operation in next cell as below:
tweets['{first_key}'] = tweets['text'].str.contains(r"^(?=.*\b{first_key}\b).*$", case=False) == True
tweets['{second_key}'] = tweets['text'].str.contains(r"^(?=.*\b'{second_key}'\b).*$", case=False) == True
tweets['{third_key}'] = tweets['text'].str.contains(r"^(?=.*\b'{third_key}'\b).*$", case=False) == True
But results are wrong. Any idea how to get the correct results. A small snapshot of the results is like this.
