2017-04-16 3 views
-1

팬텀 데이터 프레임의 형식으로 표현 된 문서 용어 행렬을 생성하려고합니다. 여기 내 코드는 지금까지 있습니다 :문서 용어 행렬을 생성 할 때 속성 오류가 발생합니다.

df_profession['Athlete_Clean'] = df_profession['Athlete Biographies'].str.lower() 
df_profession['Athlete_Clean'] = df_profession['Athlete_Clean'].apply(lambda x: ''.join([i for i in x if not i.isdigit()])) 
df_profession['Athlete_Clean'] = df_profession['Athlete_Clean'].str.split() 
df_profession['Athlete_Clean'] = [word for word in df_profession['Athlete_Clean'] if word not in punctuation] 
df_profession['Athlete_Clean'] = [word for word in df_profession['Athlete_Clean'] if word not in stopwords.words('english')] 

profession_dtm_athlete = pandas.DataFrame(countvec.fit_transform(df_profession['Athlete_Clean']).toarray(), columns=countvec.get_feature_names(), index = df.index) 
profession_dtm_athlete 

나는 다음과 같은 오류가이 코드를 실행하면 :

'list' object has no attribute 'lower' 
나는이 오류를 제거 할 수 있습니까

?

답변

0

랩 목록은 문자열로 변환하는 STR()에서 객체 :

df_profession['Athlete_Clean'] = str(df_profession['Athlete Biographies']).lower() 
df_profession['Athlete_Clean'] = df_profession['Athlete_Clean'].apply(lambda x: ''.join([i for i in x if not i.isdigit()])) 
df_profession['Athlete_Clean'] = str(df_profession['Athlete_Clean']).split() 
df_profession['Athlete_Clean'] = [word for word in df_profession['Athlete_Clean'] if word not in punctuation] 
df_profession['Athlete_Clean'] = [word for word in df_profession['Athlete_Clean'] if word not in stopwords.words('english')] 

profession_dtm_athlete = pandas.DataFrame(countvec.fit_transform(df_profession['Athlete_Clean']).toarray(), columns=countvec.get_feature_names(), index = df.index) 
profession_dtm_athlete 
+0

을 그래서 그 문제를 돌파 한 것으로 보이지만, 지금은 ValueError를 "은 받고 있어요 : 값의 길이의 길이와 일치하지 않습니다 색인 "이것이 나타나는 이유에 대한 제안? – Jberk

+0

그 오류는 pandas 라이브러리 내부에 있으므로 확실하지 않습니다. 그것은 신선한 질문을받을 수 있습니다. 새로운 질문을하면 dataframe 태그를 사용하는 것이 좋습니다. – JacobIRR

+0

알았어, JacobIRR 고마워. 이 새로운 오류에 관한 새로운 질문을 만들어 보겠습니다. – Jberk