Мой код:
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))
Выход:
TypeError Traceback (most recent call last)
in ()
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 '' as a data type
Подробнее здесь: https://stackoverflow.com/questions/786 ... ta-type-wh