Community question ยท 3 years ago

Question #360392

TypeError: expected string or bytes-like object in wordcloud in pyhon

I am trying to build wordcloud using WordCloud funtion in Python using following syntax

df = sql_query1
df.isna().sum()
word_cloud2 = WordCloud(collocations = False, background_color = 'white').generate(df["BankComment"])

it throws following error

TypeError: expected string or bytes-like object

i tried to convert bankComment to string using following methods

df["BankComment"] = df["BankComment"].replace("/"," ")
df["BankComment"] = df["BankComment"].apply(lambda x: str(x))

but nothing worked
following are entries

|/BAI/469/BAI/REF-6215077H0196 /ENTRY-18 MAR PO...|
|/BAI/469/BAI/REF-6215077H0218 /ENTRY-18 MAR PO...\|

Community responses

0 answers

Add your answer

Share the reasoning, tradeoffs, and code that make your answer useful.