我尝试使用for循环遍历数据帧,但遇到以下错误:
“ValueError:序列的真值不明确。”
我想通过“Plataforma”和“Soporte”来替换“Soporte”值。 我用的是:
for index, row in informe.iterrows():
if informe.loc[index, 'Plataforma'] == 'Taboola':
informe['Soporte'].str.replace('performance-prospecting_tconvergentes', 'Prospecting_Taboola_tconvergentes')
informe['Soporte'].str.replace('performance-prospecting_tmoviles', 'Prospecting_Taboola_tmoviles')
informe['Soporte'].str.replace('performance-prospecting', 'Prospecting_Taboola')
elif informe.loc[index, 'Plataforma'] == 'Yahoo':
informe['Soporte'].str.replace('performance-prospecting_tconvergentes', 'Prospecting_Yahoo_tconvergentes')
informe['Soporte'].str.replace('performance-prospecting_tmoviles', 'Prospecting_Yahoo_tmoviles')
informe['Soporte'].str.replace('performance-prospecting', 'Prospecting_Yahoo')
提前谢谢
首先
iterrows
是pandas中最慢的迭代解决方案之一,最好避免它,检查this answer by pandas developer Jeff因此,您可以创建用于替换的词典,使用^{} 按掩码筛选行,并使用^{} :
相关问题 更多 >
编程相关推荐