Python Forum
TypeError: expected string or bytes-like object
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: expected string or bytes-like object
#1
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?
Reply
#2
nltk.sent_tokenize is probably returning a list, its expecting a string.
check the result of lambda x: nltk.sent_tokenize(x) independently.
Reply


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

Forum Jump:

User Panel Messages

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