Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 TypeError: expected string or bytes-like object
Hi all. I'm trying run the following code and I keep getting the "TypeError: expected string or bytes-like object" error:

df_sar['sar_details_sent'] = df_sar['sar_details'].apply(lambda x: nltk.sent_tokenize(x))

The df_sar dataframe has the following columns and types:

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 258710 entries, 0 to 258709
Data columns (total 9 columns):
CASE_ID 258710 non-null int64
CASE_NUMBER 258710 non-null object
Priority 258710 non-null object
SAR_Filed_Date 258710 non-null object
SAR_Narrative 258702 non-null object
REFERRAL_SUBTYPE_ID 258710 non-null int64
ZONE_ID 258710 non-null int64
BUSINESS_INDICATOR_ID 258710 non-null int64
WORKFLOW_STATE_ID 258710 non-null int64
dtypes: int64(5), object(4)
memory usage: 17.8+ MB

Any ideas?
nltk.sent_tokenize is probably returning a list, its expecting a string.
check the result of lambda x: nltk.sent_tokenize(x) independently.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  convert a list of string+bytes into a list of strings (python 3) pacscaloupsu 4 2,446 Mar-17-2020, 07:21 AM
Last Post: markfilan
  TypeError: 'Series' object cannot be interpreted as an integer evelynow 2 3,851 Sep-11-2019, 02:43 PM
Last Post: timmahoney
  Convert 'object' to 'string' AdWill97 1 30,292 May-06-2019, 08:22 AM
Last Post: Yoriz
  ValueError: Buffer dtype mismatch, expected 'Python object' but got 'long long' MaJeFi 2 3,918 Mar-20-2019, 06:00 AM
Last Post: MaJeFi
  TypeError: 'method' object is not subscriptable ayaz786amd 1 27,385 Nov-24-2018, 11:16 AM
Last Post: j.crater

Forum Jump:

Users browsing this thread: 1 Guest(s)