根据列拆分值之一有效地更新列

时间:2016-07-29 07:54:57

标签: python dataframe

所以这是我的代码根据列'location'的拆分值条件更新了许多列值。代码工作正常,但由于它按行迭代它不够有效。任何人都可以帮助我让这段代码更快地工作吗?

I've resolved the issue with the help of dimension concept. Please see the answer below.

    flavorDimensions "country", "environment"

    productFlavors {

        A {
            dimension "country"
        }

        B {
            dimension "country"
        }

        prod {
            dimension "environment"
        }

        qa {
            dimension "environment"
        }
    }

This will create 2 x 2 x 2 = 8 build types.
AProdRelease
AProdDebug
AQaRelease
AQaDebug
Same for B country.

In order to inject values (resValue and buildConfigField) to each build type I've written small function.

android.applicationVariants.all { variant ->
      // inject values
}

if things are not clear then message me, I'll update it with more details.

1 个答案:

答案 0 :(得分:0)

'映射'是我需要的:))

def fill_county(column):
    res = ''
    location_split = column.split(':')

    for l in location_split:
        if l.strip().startswith('County'):
            res= l.strip()
            break
    return res

df['county'] = map(fill_county, df['location'])