Pandas - AcctName별로 큰 데이터 프레임을 청크로 분할
데이터 분석에서 큰 데이터 프레임으로 작업하면 종종 메모리 오류가 발생할 수 있습니다. 이 문제를 해결하려면 데이터프레임을 더 작고 관리 가능한 청크로 분할하는 것이 귀중한 전략이 될 수 있습니다. 이 문서에서는 특정 열, 특히 AcctName을 기반으로 대규모 데이터 프레임을 효율적으로 청크로 분할하는 방법을 살펴봅니다.
목록 이해를 사용하여 이 분할을 달성할 수 있습니다.
<code class="python">import numpy as np import pandas as pd # Define the chunk size n = 200,000 # Create a list to store the chunks list_df = [] # Extract unique AcctName values AcctNames = df['AcctName'].unique() # Create a dictionary of dataframes for each AcctName DataFrameDict = {acct: pd.DataFrame for acct in AcctNames} # Split the dataframe into chunks by AcctName for acct in DataFrameDict.keys(): DataFrameDict[acct] = df[df['AcctName'] == acct] # Apply your function to the chunk trans_times_2(DataFrameDict[acct]) list_df.append(DataFrameDict[acct]) # Rejoin the chunks into a single dataframe rejoined_df = pd.concat(list_df)</code>
또는 다음을 수행할 수 있습니다. NumPy의 array_split 함수 활용:
<code class="python">list_df = np.array_split(df, math.ceil(len(df) / n))</code>
이 접근 방식은 개별적으로 액세스할 수 있는 청크 목록을 생성합니다.
원래 데이터 프레임을 재조립하려면 pd.concat을 사용하면 됩니다.
<code class="python">rejoined_df = pd.concat(list_df)</code>
이러한 기술을 활용하면 대규모 데이터 프레임을 작은 청크로 효과적으로 분할하고 필요한 변환을 적용한 다음 결과 데이터를 단일 데이터 프레임으로 재조립할 수 있습니다. 이 접근 방식을 사용하면 메모리 사용량을 크게 줄이고 데이터 처리 작업의 효율성을 높일 수 있습니다.
위 내용은 AcctName별로 대형 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 최신 버전

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

SecList
SecLists는 최고의 보안 테스터의 동반자입니다. 보안 평가 시 자주 사용되는 다양한 유형의 목록을 한 곳에 모아 놓은 것입니다. SecLists는 보안 테스터에게 필요할 수 있는 모든 목록을 편리하게 제공하여 보안 테스트를 더욱 효율적이고 생산적으로 만드는 데 도움이 됩니다. 목록 유형에는 사용자 이름, 비밀번호, URL, 퍼징 페이로드, 민감한 데이터 패턴, 웹 셸 등이 포함됩니다. 테스터는 이 저장소를 새로운 테스트 시스템으로 간단히 가져올 수 있으며 필요한 모든 유형의 목록에 액세스할 수 있습니다.

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

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구