擅长:python、mysql、java
<p>使用<code>pandas</code>,我们可以执行以下操作:</p>
<pre><code>import pandas as pd
rowsOfLines = pd.read_table('my_file.txt', header=None)
with open('output_file.txt', 'w+') as file:
for index, row in rowsOfLines.iterrows():
splitLine = row.str.split()[0]
if 'Account-No' in splitLine:
file.write('{} \n'.format(row.to_string(index=False)))
elif 'Amount:' in splitLine:
file.write('{} \n'.format(row.to_string(index=False)))
</code></pre>