Python/Python For Analytics
[Python] numpy setdiff1d(차집합)을 이용한 2개의 텍스트 파일 비교
Pydole
2019. 10. 30. 12:20
numpy.setdiff1d(array1, array2) : 2개의 array의 차집합
A_file.txt | B_file.txt |
Tomatoes are red
|
Tomatoes are red
|
import pandas as pd
import numpy as np
df_A = pd.read_csv('A_file.txt', names=['data_A'])
df_B = pd.read_csv('B_file.txt', names=['data_B'])
list_A = np.array(df_A['data_A'].tolist()) # df를 리스트로 변환
list_B = np.array(df_B['data_B'].tolist()) #
for x in np.setdiff1d(list_A,list_B): # np 차집합
print(x)
-----------------------------------------------------
Oranges are orange
Strawberries are red