Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- python
- 다이어트
- ASP
- PyQt
- tensorflow
- flutter
- urllib
- node.js
- Unity
- 리눅스
- PyQt5
- 맛집
- javascript
- ubuntu
- port
- sqlite
- mssql
- 함수
- 라즈베리파이
- GIT
- PER
- 날짜
- Linux
- swift
- IOS
- MySQL
- pandas
- MS-SQL
- Excel
- 유니티
Archives
아미(아름다운미소)
아래는 두 개의 동일한 구조를 가진 데이터프레임을 생성하고, 두 데이터프레임의 값을 비교하여 **틀린 행을 찾아내는 예제** 본문
랭귀지/pandas
아래는 두 개의 동일한 구조를 가진 데이터프레임을 생성하고, 두 데이터프레임의 값을 비교하여 **틀린 행을 찾아내는 예제**
유키공 2025. 2. 18. 13:56import pandas as pd
# 샘플 데이터 생성
data1 = {
'id': [1, 2, 3, 4, 5],
'name': ['Alice', 'Bob', 'Charlie', 'David', 'Eva'],
'age': [25, 30, 35, 40, 45],
'city': ['New York', 'Los Angeles', 'Chicago', 'Houston', 'Phoenix']
}
data2 = {
'id': [1, 2, 3, 4, 5],
'name': ['Alice', 'Bob', 'Charlie', 'Daniel', 'Eva'], # 'David' -> 'Daniel'
'age': [25, 30, 35, 40, 50], # 45 -> 50
'city': ['New York', 'Los Angeles', 'Chicago', 'Houston', 'Phoenix']
}
# 데이터프레임 생성
df1 = pd.DataFrame(data1)
df2 = pd.DataFrame(data2)
# 두 데이터프레임 비교
comparison = df1.compare(df2)
# 틀린 행 찾기 (boolean indexing 사용)
mismatch_rows = df1[df1.ne(df2).any(axis=1)]
print("두 데이터프레임 비교 결과:")
print(comparison)
print("\n틀린 행:")
print(mismatch_rows)
# 틀린 행 찾기 (직접 비교)
mismatch_rows = df1[df1 != df2].dropna(how='all')
print("\n직접 비교한 틀린 행:")
print(mismatch_rows)
'랭귀지 > pandas' 카테고리의 다른 글
일수를 datetime.timedelta 변환 (0) | 2025.02.26 |
---|---|
주차를 일자로변경 (0) | 2025.02.25 |
Pandas에서 특정 조건을 만족하지 않을 경우, 날짜 열을 비교하여 한 주 전의 값을 가져오기 (0) | 2025.02.18 |
np.select (0) | 2025.02.13 |
bool 결측치 처리 (0) | 2025.02.04 |
Comments