擅长:python、mysql、java
<p>即使不使用任何库,使用csv也相当容易。在</p>
<p>首先打开该文件(我假设您在变量<code>filename</code>中保存了路径),然后使用<code>readlines()</code>函数读取该文件,然后根据您给出的条件过滤掉。在</p>
<pre><code>with open(filename, 'r') as csv: # Open the file for reading
rows = [line.split(',') for line in csv.readlines()] # Read each the file in lines, and split on commas
filter = [line[0] for line in rows if abs(float(line[1])) < 1]
# Filter out all lines where the second value is not equal to 1
</code></pre>
<hr/>
<p>这是公认的答案,所以我添加了一个免责声明。有许多原因说明,不应该毫无考虑地将此代码应用于其他csv。在</p>
<ul>
<li>它读取内存中的整个CSV</li>
<li>它不包括引用</li>
</ul>
<p>对于非常简单的CSV来说这是可以接受的,但是如果您不能确定CSV不会破坏这段代码,那么这里的其他答案会更好。在</p>