Python Forum

Full Version: TypeError: expected string or bytes-like object
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.