두 개의 데이터 프레임 비교 및 차이점 식별
시나리오에는 구조와 행 인덱스가 동일한 두 개의 데이터 프레임 df1과 df2가 있습니다. 목표는 날짜와 과일 값을 비교하여 df2에는 있지만 df1에는 없는 행을 확인하는 것입니다.
직접 비교
df1 != df2 사용 방식 동일하게 레이블이 지정된 데이터 프레임이 필요하기 때문에 적합하지 않습니다. 날짜 인덱스를 제거해도 문제가 해결되지 않습니다.
연결 및 그룹화
차이점을 찾으려면 데이터 프레임을 단일 데이터 프레임 df로 연결할 수 있습니다.
<code class="python">import pandas as pd df = pd.concat([df1, df2]) df = df.reset_index(drop=True)</code>
모든 열을 기준으로 df를 그룹화하여 고유 레코드 식별:
<code class="python">df_gpby = df.groupby(list(df.columns))</code>
고유 레코드 필터링
다음으로 고유 레코드의 인덱스를 검색합니다. , 이는 그룹 크기가 1:
<code class="python">idx = [x[0] for x in df_gpby.groups.values() if len(x) == 1]</code>
마지막으로 이러한 인덱스를 사용하여 연결된 데이터 프레임을 필터링하여 df2에만 있는 행만 얻을 수 있습니다:
<code class="python">df.reindex(idx)</code>
이렇게 하면 원하는 차이점이 포함된 데이터프레임이 반환됩니다.
Date Fruit Num Color 9 2013-11-25 Orange 8.6 Orange 8 2013-11-25 Apple 22.1 Red
위 내용은 두 데이터프레임을 비교하고 특정 열을 기반으로 차이점을 추출하는 방법은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

Pythonusesahybridmodelofilationandlostretation : 1) ThePyThoninterPretreCeterCompileSsourcodeIntOplatform-IndependentBecode.

Pythonisbothingretedandcompiled.1) 1) it 'scompiledtobytecodeforportabilityacrossplatforms.2) thebytecodeisthentenningreted, withfordiNamictyTeNgreted, WhithItmayBowerShiledlanguges.

forloopsareusedwhendumberofitessiskNowninadvance, whilewhiloopsareusedwhentheationsdepernationsorarrays.2) whiloopsureatableforscenarioScontiLaspecOndCond

pythonisnotpurelynlogreted; itusesahybrideprophorfbyodecodecompilationandruntime -INGRETATION.1) pythoncompilessourcecodeintobytecode, thepythonVirtualMachine (pvm)

ToconcatenatelistsinpythonwithesameElements, 사용 : 1) OperatorTokeEpduplicates, 2) asettoremovedUplicates, or3) listComperensionForControlOverDuplicates, 각 methodHasDifferentPerferformanCeanDorderImpestications.

PythonisancerpretedLanguage, 비판적 요소를 제시하는 PytherfaceLockelimitationsIncriticalApplications.1) 해석 된 언어와 같은 thePeedBackandbackandrapidProtoTyping.2) CompilledlanguagesLikec/C transformt 해석

useforloopswhhenmerfiterationsiskNownInAdvance 및 WhileLoopSweHeniTesslationsDepoyConditionismet whilEroopsSuitsCenarioswhereTheLoopScenarioswhereTheLoopScenarioswhereTheLoopScenarioswhereTherInatismet, 유용한 광고 인 푸트 gorit


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

SublimeText3 영어 버전
권장 사항: Win 버전, 코드 프롬프트 지원!

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

ZendStudio 13.5.1 맥
강력한 PHP 통합 개발 환경

안전한 시험 브라우저
안전한 시험 브라우저는 온라인 시험을 안전하게 치르기 위한 보안 브라우저 환경입니다. 이 소프트웨어는 모든 컴퓨터를 안전한 워크스테이션으로 바꿔줍니다. 이는 모든 유틸리티에 대한 액세스를 제어하고 학생들이 승인되지 않은 리소스를 사용하는 것을 방지합니다.

VSCode Windows 64비트 다운로드
Microsoft에서 출시한 강력한 무료 IDE 편집기