TypeError : '<class'str '>'유형의 개체를 연결할 수 없습니다. Series 및 DataFrame obj 만 유효합니다.

user1120

car_A를 호출 한 내 데이터 :

    Source
0   CAULAINCOURT
1   MARCHE DE L'EUROPE
2   AU MAIRE

소스에서 대상까지의 모든 경로에서 다음과 같이 찾고 싶습니다.


    Source                    Destination
0 CAULAINCOURT           MARCHE  DE L'EUROPE
2 CAULAINCOURT                AU MAIRE
3 MARCHE DE L'EUROPE        AU MAIRE
.
.
.

나는 이미 시도했다

for i in car_A['Names']:
  for j in range(len(car_A)-1):
    car_A = car_A.append(car_A.iloc[j+1,0])

하지만 나는

TypeError: cannot concatenate object of type '<class 'str'>'; only Series and DataFrame objs are valid

언급 된 데이터 세트는 어떻게 얻을 수 있나요?

제임스

를 사용 itertools.product하여 모든 쌍의 집합을 만들고, 원본과 대상이 동일한 위치에있을 때 제거하도록 필터링 한 다음 새 데이터 프레임을 구성 할 수 있습니다.

import pandas as pd
from itertools import product

df = pd.DataFrame({'sources': [
    "CAULAINCOURT",
    "MARCHE DE L'EUROPE",
    "AU MAIRE"
]})

df_pairs = pd.DataFrame(
    filter(lambda x: x[0]!=x[1], product(df.sources, df.sources)), 
    columns=['source', 'dest']
)

df_pairs
# returns:
               source                dest
0        CAULAINCOURT  MARCHE DE L'EUROPE
1        CAULAINCOURT            AU MAIRE
2  MARCHE DE L'EUROPE        CAULAINCOURT
3  MARCHE DE L'EUROPE            AU MAIRE
4            AU MAIRE        CAULAINCOURT
5            AU MAIRE  MARCHE DE L'EUROPE


이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관