【发布时间】:2016-07-29 07:54:56
【问题描述】:
所以这是我的代码根据列“位置”的拆分值条件更新许多列值。该代码工作正常,但由于它按行迭代,效率不够高。谁能帮我加快这段代码的运行速度?
for index, row in df.iterrows():
print index
location_split =row['location'].split(':')
after_county=False
after_province=False
for l in location_split:
if l.strip().endswith('ED'):
df[index, 'electoral_district'] = l
elif l.strip().startswith('County'):
df[index, 'county'] = l
after_county = True
elif after_province ==True:
if l.strip()!='Ireland':
df[index, 'dublin_postal_district'] = l
elif after_county==True:
df[index, 'province'] = l.strip()
after_province = True
【问题讨论】: