I have a dataframe with approx. 10,000 rows and 10 columns. And I have a string, which I want to search for in the dataframe, called 'atmosphere'. This string can only be found once in a row. I want to keep only the cells that contain this string, but with their whole content, and save them in a new column. I already found the following solution, but it only gives me back "True" (when cell contains string) or "False" (when it does not).:
df.apply(lambda col: col.str.contains('atmosphere', case=False), axis=1)
Output:
col_1 col_2 col_3 col_4 ...
1 True False False False
2 False True False False
3 True False False False
...
How can I get from this, to this?:
new_col
1 today**atmosphere**is
2 **atmosphere**humid
3 the**atmosphere**now
.extract()method.df.head().to_dict()in your question