从字符串数组中删除某些符号

时间:2018-02-26 19:46:52

标签: python string numpy

我有一个带字符串的numpy.ndarray。我创建了一个字符列表,我想对字符串数组使用,以删除字符列表中出现的所有字符。我想将符号自由字符串放在一个新数组中。我怎么能这样做?

输入:

symbols = string.printable[62:]
symbolsList = list(symbols)
symbolsList

输出:

['!',
 '"',
 '#',
 '$',
 '%',
 '&',
 "'",
 '(',
 ')',
 '*',
 '+',
 ',',
 '-',
 '.',
 '/',
 ':',
 ';',
 '<',
 '=',
 '>',
 '?',
 '@',
 '[',
 '\\',
 ']',
 '^',
 '_',
 '`',
 '{',
 '|',
 '}',
 '~',
 ' ',
 '\t',
 '\n',
 '\r',
 '\x0b',
 '\x0c']

string_array的示例输出:

array(['[KFC] CHicken_Gravy_Coke_Biscuit This is my Order!!!<lf><lf>', dtype=object)

我希望它看起来像这样:

  array(['KFC CHicken Gravy Coke Biscuit This is my Order  lf lf', dtype=object)

我试过了:

cleanData = []
for i in string_array:
        cleanData.append(string_array[i].replace(symbolsList[i], " "))

和:

cleanData = []
for i in summary_data:
    cleanData = summary_data[i].replace(symbolsList[i], " ")

两者都给出相同的输出:

IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

但是不起作用:(如何使这项工作?或做我想做的事?

0 个答案:

没有答案
相关问题