2012-06-28 2 views
1

현재 다음 코드로 숫자를 롤백 중입니다. dataframe의 각 요소에 대해 합계 기준을 설정하는 몇 가지 조건이 있지만 작성된 보고서 중 가장 느린 부분입니다. 특정 문자열로 시작하는 데이터 프레임의 모든 요소를 ​​식별하는 더 빠른 방법이 있습니까?문자열을 시작으로하는 데이터 프레임 열의 모든 요소를 ​​찾습니다.

for idx, eachRecord in attributionCalcDF.T.iteritems():   
    if (attributionCalcDF['SEC_ID'].ix[idx] == 0): 

     currentGroup = lambda x: str(x).startswith(attributionCalcDF['GROUP_LIST'].ix[idx]) 
     currentGroupArray = attributionCalcDF['GROUP_LIST'].map(currentGroup) 

     attributionCalcDF['ROLLUP_DAILY_TIMING_IMPACT'].ix[idx] = (
                 attributionCalcDF['DAILY_TIMING_IMPACT'][(attributionCalcDF['SEC_ID'] != 0) & 
                 (currentGroupArray) & 
                 (attributionCalcDF['START_DATE'] == attributionCalcDF['START_DATE'].ix[idx])].sum()) 

     attributionCalcDF['ROLLUP_DAILY_STOCK_TO_GROUP_IMPACT'].ix[idx] = (
                 attributionCalcDF['DAILY_STOCK_TO_GROUP_IMPACT'][(attributionCalcDF['SEC_ID'] != 0) & 
                 (currentGroupArray) & 
                 (attributionCalcDF['START_DATE'] == attributionCalcDF['START_DATE'].ix[idx])].sum()) 

답변

1

당신은 아마 currentGroup 기능의이 부분 타격을하고있어 :

attributionCalcDF['GROUP_LIST'].ix[idx] 

임시 변수에 있음을 저장하고 startswith 내부의 임시 변수를 사용하십시오. 나는 팬더에 벡터화 된 문자열 함수를 곧 추가 할 계획이므로이 경우에도 큰 도움이 될 것입니다.

+0

감사합니다. Wes. 이 기능의 시간이 ~ 40 % 향상되었습니다. 벡터화 된 문자열 함수? ... 대단히 기대! –

관련 문제