있는 값의 조합을 찾아 내가 id_y 각 id_x의 총 조합을 찾을팬더 dataframe 열
id_x id_y
a b
b c
c d
d a
b a
and so on around (1000 rows)
DF 팬더의 테이블을 갖는다. 연결 고리와 같은 것
즉. 유사 a-b,b-c,c-d
와의 조합을 가지고 B combinations(b-c,c-d,d-a) and also a-b to be considered as a combination for b(a-b = b-a)
가 있으며
id combinations count
a b,c,d 3
b c,d,a 3
c d,a,b 3
d a,b,c 3
and so on ..(distinct product_id_'s)
및 갖는 dataframe의 DF2를 생성 제가
id c1 c2 c3...&so on count
a b c d 3
b c d a 3
dataframe의 다른 열의 각 조합을 넣을 수 있다면 어떤 접근해야합니까? 파이썬에 관한 나의 기술은 초급 단계에 있습니다. 미리 감사드립니다. 이것은 다음과 같은 결과 제공
#generate dataframe
pdf = pd.DataFrame(dict(id_x = ['a','b','c','d','b'], id_y = ['b', 'c', 'd', 'a', 'a']))
#generate second dataframe with swapped columns:
pdf_swapped = pdf.rename(columns = dict(id_x= 'id_y', id_y= 'id_x'))
#append both dataframes to each other
pdf_doubled = pd.concat([pdf, dummy_pdf])
#evaluate the frequency of each combination:
result = pdf_doubled.groupby('id_x').apply(lambda x: x.id_y.value_counts())
:
당신이하고 싶은 일에 대해 더 분명히 밝혀야합니다. 또한, 그것을 할 몇 가지 코드를 작성하십시오. –
더 복잡합니다. 입력에서 모든 출력 조합을 추가 할 수 있다고 생각합니다. 정확히 무엇이 필요한지 명확하지 않습니다. 고맙습니다. – jezrael
@jezrael에서 a -> b 및 b -> c 및 c -> d를 이렇게 a에 대한 체인은 'a -> b, c, d'를 가져야합니다. – Shubham