首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >删除数据集中的符号

删除数据集中的符号
EN

Stack Overflow用户
提问于 2021-05-10 02:58:07
回答 1查看 223关注 0票数 2

我应用了所有预处理步骤,但我想删除具有英文单词或特定符号的行,只是我希望阿拉伯语中的单词没有这些符号或我在下面代码中提到的英文单词。我应用了代码,但是当我在清理后打印数据集时,它仍然没有清理!我想移除它而不是替换它。

代码语言:javascript
复制
lexicon = pd.read_csv(r"C:\Users\User\Python Code\data.csv")
lexicon.head(10)

#output
    Vocabulary
0   [PAD]
1   [UNK]
2   [CLS]
3   [SEP]
4   [MASK]
5   !
6   #
7   $
8   %
9   &

lexicon['clean_tweet'] = lexicon.Vocabulary.str.replace('[^\w\s#@/:%.,_-]', '', flags=re.UNICODE) #removes emojis
lexicon['clean_tweet'] = lexicon.clean_tweet.str.replace('@[_A-Za-z0-9]+', '') #removes handles
lexicon['clean_tweet'] = lexicon.clean_tweet.str.replace('[A-Za-z0-9]+', '') #removes english
lexicon['clean_tweet'] = lexicon.clean_tweet.str.replace('#',' ') #removes hashtag symbol only
lexicon['clean_tweet'] = lexicon.clean_tweet.str.replace(r'http\S+', '', regex=True).replace(r'www\S+', '', regex=True) #removes links
lexicon['clean_tweet'] = lexicon.clean_tweet.str.replace('\d+', '') #removes numbers
lexicon['clean_tweet'] = lexicon.clean_tweet.str.replace('\n', ' ') #removes new line
lexicon['clean_tweet'] = lexicon.clean_tweet.str.replace('_', '') #removes underscore
lexicon['clean_tweet'] = lexicon.clean_tweet.str.replace('[^\w\s]','') #removes punctuation
lexicon.head(10)

# Vocabulary    clean_tweet
0   [PAD]   
1   [UNK]   
2   [CLS]   
3   [SEP]   
4   [MASK]  
5   !   
6   #   
7   $   
8   %   
9   &   

我想删除所有包含这些符号或任何语言的行,只是我需要阿拉伯词,还是有另一种简单的方法只检测阿拉伯单词?

注意:如果行包含阿拉伯单词和符号,我只想删除没有阿拉伯词的符号。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-10 03:11:04

通过this SO answer,对阿拉伯字母的Unicode正则表达式范围是:

代码语言:javascript
复制
[\u0627-\u064a]

我们可以尝试使用此字符类的负面版本以及str.replace

代码语言:javascript
复制
lexicon['clean_tweet'] = lexicon.clean_tweet.str.replace(r'[^\u0627-\u064a]', '')

如果要保留空格字符或其他标点符号,则可以尝试使用以下正则表达式:

代码语言:javascript
复制
[^\u0627-\u064a\s!?.-]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67464241

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档