2021-07-11 20:58:19
CSV文件本质上就是文本文件,只不过每行的数据用逗号分隔。
所以你当成文本文件打开一行一行的读然后拆分就可以了。
1 2 3 4 5 6 7 8 9 10 |
还有就是可以用Pandas这个库,dataframe有导入csv功能。
data = []with open(r'd:\temp\demo.csv', 'r') as csv_file: for line in csv_file: data.append(line.strip().split(','))print(data)# 另外Python标准库里有个CSV模块可以用。import csvwith open(file_path, 'rb') as csv_file: data = list(csv.reader(csv_file))[1:] # 去掉首行的列名
2021-08-28 04:27:43
2020-05-01 15:35:54
2021-05-08 08:08:16
1 2 3 4 5 |
2021-05-14 12:41:00
Python 2.7.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170118] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import csv>>> help(csv)