2017-11-20 13 views
1

여러 통화에 국제 통화 기호가있는 Excel 파일 작업. 그 외에도 일부 국제어 파일도 있습니다. 방법은 제거하기 위해 만들어졌습니다 :팬더 데이터 프레임이 국제 통화 기호를 대체합니다.

이 외에도 - (환영보다 더 많은 방법이 더 효율적이있는 경우) 작업을 다음 정리 프로세스가

df = df.apply(lambda x: x.str.replace('\\r',' ')) 
df = df.apply(lambda x: x.str.replace('\\n',' ')) 
df = df.apply(lambda x: x.str.replace('\.+', '')) 
df = df.apply(lambda x: x.str.replace('-', '')) 
df = df.apply(lambda x: x.str.replace('&', '')) 
df = df.apply(lambda x: x.str.replace(r"[\"\',]", '')) 
df = df.apply(lambda x: x.str.replace('[%*]', ''), axis=1) 

을 촬영 한 것처럼

Example: Paying £40.50 doesn't make any sense for a one-hour parking. 
Example: Produkty są zbyt drogie (Polish) 
Example: 15% de la population féminine n'obtient pas de bons emplois (French) 

불용어

def cleanup(row): 
    stops = set(stopwords.words('english')) 
    removedStopWords = " ".join([str(i) for i in row.lower().split() 
    return removedStopWords 

데이터 프레임 t의 모든 열에이 방법을 적용하려면

df = df.applymap(self._row_cleaner)['ComplainColumns'] 

을하지만 가장 큰 문제 UnicodeEncodeError있다 : 모자는 예 이상 포함되어 있습니다. 영국 파운드시에이 오류가 발생하는 첫 번째 장소 중 하나입니다.

UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in position 646: ordinal not in range(128)

다음 시도 : df = df.apply(lambda x: x.unicode.replace(u'\xa3', '')) 창자가 작동하지 않았다.

목표는 이외의 모든 문자를 바꾸려면 '' 또는 ' '

+1

이렇게하면'df = df.replace ('[^ \ w \ s]', '', regex = True)를 도움이 될까요? – Dark

+0

그것은 모든 것을 w로 바꿔 놓았습니다. –

+0

AttributeError : ("float '객체에'lower '속성이 없습니다. 색인에 u'ccurred가 있습니다.')'내부 정리 메소드'removedStopWords =" ".join ([str (i) for row.lower(). split()이 멈추지 않았다면])' –

답변

1

모든 없음 알파벳 문자를 대체하는 것입니다 [A-Z0-9] 당신은 즉, 정규 표현식으로 대체 사용할 수 있습니다

df = df.replace('[^\w\s]','',regex=True) 

데이터 프레임에 데이터가 누락되어 있으므로 astype (str)을 사용해야 할 수도 있습니다. 목록 이해력을 .lower()과 함께 사용하고 있기 때문에 Nan은 float로 간주됩니다.

df.astype(str).apply(cleanup)