팬더 조인 문제 : 열이 겹치지 만 접미사가 지정되지 않았습니다.
다음과 같은 2 개의 데이터 프레임이 있습니다.
df_a =
mukey DI PI
0 100000 35 14
1 1000005 44 14
2 1000006 44 14
3 1000007 43 13
4 1000008 43 13
df_b =
mukey niccdcd
0 190236 4
1 190237 6
2 190238 7
3 190239 4
4 190240 7
이 두 데이터 프레임에 참여하려고하면 :
join_df = df_a.join(df_b,on='mukey',how='left')
오류가 발생합니다.
*** ValueError: columns overlap but no suffix specified: Index([u'mukey'], dtype='object')
왜 그렇습니까? 데이터 프레임에는 공통 'mukey'값이 있습니다.
게시 한 데이터 스 니펫에 대한 오류는 약간의 암호입니다. 공통 값이 없기 때문에 값이 겹치지 않기 때문에 조인 작업이 실패합니다. 왼쪽과 오른쪽에 접미사를 제공해야합니다.
In [173]:
df_a.join(df_b, on='mukey', how='left', lsuffix='_left', rsuffix='_right')
Out[173]:
mukey_left DI PI mukey_right niccdcd
index
0 100000 35 14 NaN NaN
1 1000005 44 14 NaN NaN
2 1000006 44 14 NaN NaN
3 1000007 43 13 NaN NaN
4 1000008 43 13 NaN NaN
merge
이 제한이 없기 때문에 작동합니다.
In [176]:
df_a.merge(df_b, on='mukey', how='left')
Out[176]:
mukey DI PI niccdcd
0 100000 35 14 NaN
1 1000005 44 14 NaN
2 1000006 44 14 NaN
3 1000007 43 13 NaN
4 1000008 43 13 NaN
.join()
기능은 사용 index
사용한다, 그래서 인수 데이터 세트로 전달의를 set_index
또는 사용 .merge
대신에 기능.
귀하의 경우에 적합한 두 가지 예를 찾으십시오.
join_df = LS_sgo.join(MSU_pi.set_index('mukey'), on='mukey', how='left')
또는
join_df = df_a.merge(df_b, on='mukey', how='left')
This error indicates that the two tables have the 1 or more column names that have the same column name. The error message translates to: "I can see the same column in both tables but you haven't told me to rename either before bringing one of them in"
You either want to delete one of the columns before bringing it in from the other on using del df['column name'], or use lsuffix to re-write the original column, or rsuffix to rename the one that is being brought it.
df_a.join(df_b, on='mukey', how='left', lsuffix='_left', rsuffix='_right')
'IT박스' 카테고리의 다른 글
왜 항상 ./configure; (0) | 2020.07.29 |
---|---|
특정 문자열 상수를 제외하는 RegEx (0) | 2020.07.29 |
Windows Azure : 웹 역할, 작업자 역할 및 VM 역할이란 무엇입니까? (0) | 2020.07.29 |
jQuery로 요소 컨텐츠 변경 감지 (0) | 2020.07.29 |
간단한 개발 및 배포를 위해 Django를 어떻게 구성합니까? (0) | 2020.07.29 |