[Python] Pandas dataframe 합치기 (concat, merge, join)
#결과 B C D A a1 b1 c1 d1 a2 b2 c2 d2 1. concat import pandas as pd df1 = pd.DataFrame({'A':['a1', 'a2', 'a3'], 'B':['b1', 'b2', 'b3'], 'C':['c1', 'c2', 'c3']}) df2 = pd.DataFrame({'A':['a4', 'a5', 'a6'], 'D':['d1', 'd2', 'd3']}) 위 데이터 프레임을 사용해 연습해보자 result = pd.concat([df1, df2]) print(result) # 결과 A B C D 0 a1 b1 c1 NaN 1 a2 b2 c2 NaN 2 a3 b3 c3 NaN 0 a4 NaN NaN d1 1 a5 NaN NaN d2 2 a6 NaN NaN d..
2021. 11. 29.
[Python] Pandas dataframe 'isin' & 'not in' 사용법
1. IN 데이터 프레임 A와 B에서 공통되는 부분을 찾고 싶은 경우 in 을 사용할 수 있다. 간단한 예제를 통해 in을 사용하는 경우를 살펴보자 A = pd.DataFrame({'fruits': ['strawberry', 'banana', 'cranberry', 'apple', 'orange'] , 'price': ['1000', '2000', '1500', '500', '2500']}) B = ['strawberry', 'cranberry'] A는 fruits, price 두 개의 열로 이루어진 데이터 프레임 이며, B는 리스트이다. A의 fruits에서 B에 있는 과일만 골라서 보고싶은 경우, 아래처럼 코드를 작성할 수 있다. df = A[A.fruits.isin(B)] 위 코드를 작성할 경우 B..
2021. 11. 29.