How to use the split function on every row in a dataframe in Python?

前端 未结 4 1570
一向
一向 2021-02-04 05:32

I want to count the number of times a word is being repeated in the review string

I am reading the csv file and storing it in a python dataframe using the below line

4条回答
  •  不思量自难忘°
    2021-02-04 06:21

    You're trying to split the entire review column of the data frame (which is the Series mentioned in the error message). What you want to do is apply a function to each row of the data frame, which you can do by calling apply on the data frame:

    f = lambda x: len(x["review"].split("disappointed")) -1
    reviews["disappointed"] = reviews.apply(f, axis=1)
    

提交回复
热议问题