My coding
Cleaning
import re
Remove mentions (@username)
df[‘full_text’] = df[‘full_text’].astype(str).apply(lambda x: re.sub(r’@w+’, ”, x))
Remove hashtags (#hashtag)
df[‘full_text’] = df[‘full_text’].astype(str).apply(lambda x: re.sub(r’#w+’, ”, x))
Remove links (http:// or https://)
df[‘full_text’] = df[‘full_text’].astype(str).apply(lambda x: re.sub(r’https?://S+’, ”, x))
df[‘full_text’] = df[‘full_text’].astype(str).apply(lambda x: re.sub(r’www.S+’, ”,x))
the output
TypeError Traceback (most recent call last)
in <cell line: 4>()
2 import re
3 # Remove mentions (@username)
—-> 4 df[‘full_text’] = df[‘full_text’].astype(str).apply(lambda x: re.sub(r’@w+’, ”, x))
5 # Remove hashtags (#hashtag)
6 df[‘full_text’] = df[‘full_text’].astype(str).apply(lambda x: re.sub(r’#w+’, ”, x))
5 frames
/usr/local/lib/python3.10/dist-packages/pandas/core/dtypes/common.py in pandas_dtype(dtype)
1689 # Hence enabling DeprecationWarning
1690 warnings.simplefilter(“always”, DeprecationWarning)
-> 1691 npdtype = np.dtype(dtype)
1692 except SyntaxError as err:
1693 # np.dtype uses eval
which can raise SyntaxError
TypeError: Cannot interpret ‘<module ‘string’ from ‘/usr/lib/python3.10/string.py’>’ as a data type
I was trying my coding with search using Blackbox.ai and I was stuck.
20200801015 Joko Sulistyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.