Python Forum
Apply function on different columns as defined
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Apply function on different columns as defined
#7
Hi

I am also facing the same issue.

I have a dataframe named with columns: label,text

I defined function as below:
def split_tokens(text):
    message = text.str.lower()
    word_tokens = word_tokenize(message)
    return word_tokens
I am applying this function on a new dataframe column as below
imdb['tokenized_message'] = imdb[['text']].apply(split_tokens,axis=1)
But when I execute this function I get error with message:
Quote:TypeError: ('expected string or bytes-like object', 'occurred at index 0')

Can anyone please help.

Thanks
Reply


Messages In This Thread
RE: Apply function on different columns as defined - by vivekirti - Sep-04-2019, 03:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  apply(pd.Series) until no more array mikisDeWitte 1 2,792 Apr-17-2021, 08:45 PM
Last Post: Caprone
  Outputs "NaN" after "DataFrame columns" function? epsilon 7 3,696 Jan-27-2021, 10:59 AM
Last Post: epsilon
  A function to return only certain columns with certain string illmattic 2 2,227 Jul-24-2020, 12:57 PM
Last Post: illmattic
  Apply rolling window function over time dimension of 3D data Staph 0 2,201 Jan-01-2020, 08:31 AM
Last Post: Staph
  Filter value from DataFrame apply a function and save to xlsx zinho 1 2,044 Dec-22-2019, 03:54 PM
Last Post: zinho
  how to apply user defined function to Pandas DataFrame evelynow 3 7,663 Aug-20-2019, 11:35 PM
Last Post: scidam
  Apply Method Question smw10c 4 5,575 Apr-08-2017, 12:47 PM
Last Post: smw10c

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020