我目前正在使用以下代码汇总数字。对于 中的每个元素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())