擅长:python、mysql、java
<p>你就快到了。问题出在划分<code>cnt = len(parsedlist/2)</code>的地方</p>
<p>更正代码:</p>
<pre><code>def createxm(x):
try:
parsedlist = x['strings'].split('|')
print(parsedlist)
cnt = len(parsedlist)
print(cnt)
xm_list = []
for i in range(0, int(cnt), 2):
xm_list.append('<thekeys db="{}" value="{}"/>'.format(parsedlist[i], parsedlist[i+1]))
xm_string = '\n'.join(xm_list)
return xm_string
except:
return None
df['new_col'] = df.apply(lambda x:createxm(x), axis=1)
</code></pre>
<p>印刷品:</p>
<pre><code>df.new_col.iloc[1]
'<thekeys db="tef" value="fe4545"/>\n<thekeys db="tef" value="fe3333"/>\n<thekeys db="tef" value="9995"/>'
</code></pre>