피벗을 위한 DataFrame 전치
DataFrame 피벗은 행과 열을 전치하여 데이터를 다르게 표현하는 것을 의미합니다. Pandas에서는 이러한 목적으로 피봇 방법을 사용할 수 있습니다.
다음 DataFrame을 고려하세요.
Indicator Country Year Value 1 Angola 2005 6 2 Angola 2005 13 3 Angola 2005 10 4 Angola 2005 11 5 Angola 2005 5 1 Angola 2006 3 2 Angola 2006 2 3 Angola 2006 7 4 Angola 2006 3 5 Angola 2006 6
이 DataFrame을 피벗하여 표시기 값을 새 열로 가지려면:
out = df.pivot(columns = 'Country', 'Year', 'Indicator', values = 'Value') print(out)
결과는 다음과 같습니다.
Indicator 1 2 3 4 5 Country Year Angola 2005 6 13 10 11 5 2006 3 2 7 3 6
비피봇 상태로 되돌리려면 형식:
print(out.rename_axis(columns=None).reset_index())
이 결과는 다음과 같습니다.
Country Year 1 2 3 4 5 0 Angola 2005 6 13 10 11 5 1 Angola 2006 3 2 7 3 6
.pivot_table 사용
중복된 레이블 조합이 있는 경우 피벗_테이블을 활용할 수 있습니다. 기본적으로 평균을 계산합니다.
out = df.pivot_table( index=['Country', 'Year'], columns='Indicator', values='Value') print(out.rename_axis(columns=None).reset_index())
결과:
Country Year 1 2 3 4 5 0 Angola 2005 6.0 13.0 10.0 11.0 5.0 1 Angola 2006 3.0 2.0 7.0 3.0 6.0
자세한 내용은 형태 변경 및 피벗 테이블에 대한 Pandas 사용자 가이드를 참조하세요.
위 내용은 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 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

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

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

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

Dreamweaver Mac版
시각적 웹 개발 도구