저는 pandas
을 처음 접했고 데이터 프레임이 주어지면서 특정 요구 사항을 충족시키지 못하는 열을 일부 삭제하려고했습니다.값이 DataFrame에서 슬라이스 복사본에 설정하려고합니다. - pandas
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
self[name] = value
내가 '때문에 수행 할 작업에 대한 확실하지 않다 : 프레임을 처리 할 때
df = df.loc[df['DS_FAMILIA_PROD'].isin(['CARTOES', 'CARTÕES'])]
그러나, 나는이 오류가 발생합니다 : 그것을 수행하는 방법을 검토 한 결과, 나는이 구조에 도착 이미 .loc
기능을 사용 중입니다. 내가 무엇이 누락 되었습니까?
f = ['ID_manifest', 'issue_date', 'channel', 'product', 'ID_client', 'desc_manifest']
df = pd.DataFrame(columns=f)
for chunk in df2017_chunks:
aux = preProcess(chunk, f)
df = pd.concat([df, aux])
def preProcess(df, f):
stops = list(stopwords.words("portuguese"))
stops.extend(['reclama', 'cliente', 'santander', 'cartao', 'cartão'])
df = df.loc[df['DS_FAMILIA_PROD'].isin(['CARTOES', 'CARTÕES'])]
df.columns = f
df.desc_manifest = df.desc_manifest.str.lower() # All lower case
df.desc_manifest = df.desc_manifest.apply(lambda x: re.sub('[^A-zÀ-ÿ]', ' ', str(x))) # Just letters
df.replace(['NaN', 'nan'], np.nan, inplace = True) # Remone nan
df.dropna(subset=['desc_manifest'], inplace=True)
df.desc_manifest = df.desc_manifest.apply(lambda x: [word for word in str(x).split() if word not in stops]) # Remove stop words
return df
코드는 OK 것 같다,하지만 난 문제가 전에 생각 - [돌아-A-보기 - 대 - 한 - 복사] 체크 (http://pandas.pydata.org/pandas-docs/stable/를 indexing.html # returning-a-view-a-copy) – jezrael
은'df = df.loc [df [ 'DS_FAMILIA_PROD'] .isin ([CARTOES ','CARTENTS '])]'행을 삭제하지 않습니다. DS_FAMILIA_PROD' 열의 값을 기반으로 열을 삭제하지 않습니까? –