我想創(chuàng)建一個函數(shù)來從熊貓數(shù)據(jù)框中刪除特殊字符,但也傳遞一個參數(shù)來保留所需的字符。def strip_characters(c, req_char = ''): spec_chars = ["!",'"',"#","%","&","'","(",")","*","+",",","-",".","/",":",";","<","=",">","?","@","[","\\","]","^","_","`","{","|","}","~","–"] new_spec = spec_chars.remove(req_char) for char in spec_chars: c = c.str.replace(char, ' ') return cdf['col'] = df['col'].apply(strip_characters,',') # passing a comma to retain the character# df['col'] = ['Dining Room', 'Pre-War', 'Laundry in Building', '&Lobby']
如何創(chuàng)建一個函數(shù)來刪除 Python 中的特殊字符以進行特征工程?
慕田峪7331174
2022-11-29 16:58:23