Timestamp SP DP
20-03-2017 10:00:01 50 60.5
20-03-2017 10:10:00 60 70
20-03-2017 10:40:01 75 80
20-03-2017 11:05:00 44 65
20-03-2017 11:25:01 98 42
20-03-2017 11:50:01 12 99
20-03-2017 12:00:05 13 54
20-03-2017 12:05:01 78 78
20-03-2017 12:59:01 15 89
20-03-2017 13:00:00 46 99
20-03-2017 13:23:01 44 45
20-03-2017 13:45:08 80 39
import csv
output = []
f = open( 'test.csv', 'r' ) #open the file in read universal mode
for line in f:
cells = line.split( "," )
output.append( ( cells[ 0 ], cells[ 1 ] ) ) #since we want the first, second column
print (output)
如何读取特定列和特定行?
期望输出:
我只想要第一列和两行
Timestamp SP
20-03-2017 10:00:01 50
20-03-2017 10:10:00 60
怎么做?
你要用熊猫来读。
然后您可以通过
或者
使用} function 或使用^{} 来限制读取量:
csv
模块,然后计算行数(使用^{或者使用
islice()
:可以使用索引切片。从源代码中读取csv。
试试看。
相关问题 更多 >
编程相关推荐