Как убрать странные символы из CSV-файла в R - PullRequest
1 голос
/ 04 мая 2020

У меня есть CSV-файл, который содержит много странных символов. Пример как показано ниже:

df = data.frame(comments = c('Korea¬Ãs Ministry of Food and Drug Safety is proposing an amendment seeking to amend the Standards and Specification','it is important to highlight:\n• Many maximum limits for drug',
                            'The European Parliament has published a decision, which aims to establish a special Committee to examine the EU¬Ãs authorization procedure'))
write.csv(df, './example.csv', row.names = FALSE)

Кто-нибудь знает, как я могу убрать эти странные символы в R (или python). Я понятия не имею, почему это происходит и как их очистить. Большое спасибо.

1 Ответ

1 голос
/ 04 мая 2020

Если предположить, что "странным" является все, что не является "обычной" буквой, числом или точкой или запятой:

gsub("[^A-z0-9\\. ,]", "", df$comment)
[1] "Koreas Ministry of Food and Drug Safety is proposing an amendment seeking to amend the Standards and Specification"                     
[2] "it is important to highlight Many maximum limits for drug"                                                                               
[3] "The European Parliament has published a decision, which aims to establish a special Committee to examine the EUs authorization procedure"

С этого момента вы можете добавить больше символов, которые разрешены.

...