Find some specific strings occur in a piece of text and store them in a new column

import pandas as pd tweets = pd.read_csv("tweets.csv") def get_specific_string(row): specific_strings = [] text = row["text"].lower() if "apple" in text or "ios" in text or "mac" in text: specific_strings.append("apple") if "google" in text or "android" in text: specific_strings.append("google") if "microsoft" in text or "windows" in text: specific_strings.append("microsoft") return ",".join(specific_strings) tweets["specific_string"] = tweets.apply(get_specific_string,axis=1)
Find some specific strings occur in a piece of text and store them in a new column.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.