擅长:python、mysql、java
<p>下面的正则表达式在每三个字段之后消除不需要的换行符和其他空格。它假定字段没有任何内部分号:</p>
<pre><code>print(re.sub(r'([^;]*);\s*([^;]*);\s*([^;]*);\s+', r'\1;\2;\3\n',
line, flags=re.M))
#New York City; Iron Man;no superpowers
#Metropolis;Superman;superpowers
#New York City;Spider-Man;superpowers
#Gotham;Batman;no superpowers
#New York City;Doctor Strange;superpowers
</code></pre>
<p>在使用Pandas之前,可以在循环中运行它来预处理文件。你知道吗</p>