You should use apply
for this task.
from io import StringIO
from io import StringIO
data = StringIO("""
Record ID Product Review
123 Tablet Battery life sucks.
456 Laptop Love the sleek design, but battery life is bad.
789 Tablet I love it, even though it sucks sometimes.
""")
df = pd.read_csv(data, sep='')
def categorize(row):
"""Gets category from row
Can access columns with dot notation, e.g., row.Product
"""
# determine categories
#return categories
df['categories'] = df.apply(categorize, axis=1)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…