擅长:python、mysql、java
<p>您可以使用<a href="http://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.Series.map.html#pandas.Series.map" rel="nofollow">^{<cd1>}</a>在一行中完成相同的操作:</p>
<pre><code>df['protocol'],df['domain'],df['path'],df['query'],df['fragment'] = zip(*df['url'].map(urlparse.urlsplit))
</code></pre>
<p>使用timeit,当在186个url上运行时,它在每个循环<code>2.31 ms</code>中运行,而不是像原来的方法那样在每个循环中<code>179 ms</code>。(但是请注意,代码没有针对重复项进行优化,它将多次通过urlparse运行相同的url。)</p>
<p>完整代码:</p>
^{pr2}$