Pandas DataFrame: 조건에 따라 특정 열 값 바꾸기
DataFrame에서는 조건에 따라 열 내의 특정 값을 바꾸는 것이 필요한 경우가 많습니다. 미리 정의된 조건. 다음 DataFrame을 고려하세요.
Team First Season Total Games 0 Dallas Cowboys 1960 894 1 Chicago Bears 1920 1357 2 Green Bay Packers 1921 1339 3 Miami Dolphins 1966 792 4 Baltimore Ravens 1996 326 5 San Franciso 49ers 1950 1003
'First Season' 열에서 1990보다 큰 모든 값을 1로 바꿔야 한다고 가정합니다. 이를 달성하려면 다음 명령을 사용할 수 있습니다.
df.loc[df['First Season'] > 1990, 'First Season'] = 1
이 줄은 대괄호 안에 지정된 조건에 따라 'First Season' 열을 선택적으로 타겟팅합니다(df['First Season'] > 1990). = 기호는 선택한 요소에 값 1을 할당하여 '첫 번째 시즌' 열만 영향을 받도록 합니다.
결과 DataFrame은 다음과 같이 표시됩니다.
Team First Season Total Games 0 Dallas Cowboys 1960 894 1 Chicago Bears 1920 1357 2 Green Bay Packers 1921 1339 3 Miami Dolphins 1966 792 4 Baltimore Ravens 1 326 5 San Franciso 49ers 1950 1003
다음이 중요합니다. 이 작업의 구문에는
- df.loc[
, ]: 부울 마스크로 지정된 행과 열을 선택합니다. - =
: 선택한 열에 지정된 값을 할당합니다.
또한 값을 바꾸는 대신 부울 표시기를 생성하는 것이 목표인 경우 조건을 사용하여 다음을 수행할 수 있습니다. 부울 시리즈를 생성한 다음 dtype을 int로 캐스팅하여 정수로 변환할 수 있습니다. 그러면 True 및 False 값이 각각 1과 0으로 변환됩니다.
위 내용은 조건에 따라 특정 Pandas DataFrame 열의 값을 어떻게 바꿀 수 있나요?의 상세 내용입니다. 자세한 내용은 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 Linux 새 버전
SublimeText3 Linux 최신 버전

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

WebStorm Mac 버전
유용한 JavaScript 개발 도구

MinGW - Windows용 미니멀리스트 GNU
이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

드림위버 CS6
시각적 웹 개발 도구