<p>假设您的数据位于这样的纯文本文件中:</p>
<pre><code>$ cat data.txt
0 4028.44 4544434.50 -6.76 -117.00 0.0002 0.12
0 4028.50 3455014.50 -5.86 0 0.0003 0.39
0 7028.56 4523434.50 -4.95 -137.00 0.0005 0.25
0 8828.62 4543414.50 -3.05 0 0.0021 0.61
0 4028.44 4544434.50 -6.76 -107.00 0.0002 0.12
0 4028.50 3455014.50 -5.86 -11.00 0.0003 0.39
0 7028.56 4523434.50 -4.95 -127.00 0.0005 0.25
0 8828.62 4543414.50 -3.05 0 0.0021 0.61
</code></pre>
<p>而且你没有使用任何外部库。下面的代码将把数据读入<code>string</code>的<code>list</code>,省略不需要的行。您可以将这些行输入到您选择的任何其他函数中。我调用<code>print</code>只是为了演示。N、 B:第五列有索引“4”,因为<code>list</code>索引是从零开始的。在</p>
^{pr2}$
<p>运行此程序时,您将获得:</p>
<pre><code>$ python data.py
1. Delete the rows which have '0' as a value on 5th column:
0 4028.44 4544434.50 -6.76 -117.00 0.0002 0.12
0 7028.56 4523434.50 -4.95 -137.00 0.0005 0.25
0 4028.44 4544434.50 -6.76 -107.00 0.0002 0.12
0 4028.50 3455014.50 -5.86 -11.00 0.0003 0.39
0 7028.56 4523434.50 -4.95 -127.00 0.0005 0.25
2. Choose the range (i.e. remove the rows which have values between -50 and 30 on 5th column):
0 4028.44 4544434.50 -6.76 -117.00 0.0002 0.12
0 7028.56 4523434.50 -4.95 -137.00 0.0005 0.25
0 4028.44 4544434.50 -6.76 -107.00 0.0002 0.12
0 7028.56 4523434.50 -4.95 -127.00 0.0005 0.25
</code></pre>