Python Forum
TypeError: expected string or bytes-like object - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: TypeError: expected string or bytes-like object (/thread-18130.html)



TypeError: expected string or bytes-like object - twinpiques - May-06-2019

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?


RE: TypeError: expected string or bytes-like object - Yoriz - May-06-2019

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