Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何读取csv文件并拆分一行?_Python_Python 3.x - Fatal编程技术网

Python 如何读取csv文件并拆分一行?

Python 如何读取csv文件并拆分一行?,python,python-3.x,Python,Python 3.x,我有一个.csv文件,当我打开该文件时,它看起来像这样 r1 r2 r3 0,3 0,3 02 43 5 3 3 3,2 01您可以使用csv.reader: import csv with open('input.csv', 'r', newline=' ') as f: reader = csv.reader(f, delimiter=' ', skipinitialspace=True) next(reader) lst = list(read

我有一个.csv文件,当我打开该文件时,它看起来像这样

r1 r2 r3
0,3  0,3  02 
43   5    3  

3 3,2 01
您可以使用
csv.reader

import csv
with open('input.csv', 'r', newline=' ') as f:
    reader = csv.reader(f, delimiter=' ', skipinitialspace=True)
    next(reader)
    lst = list(reader)
lst
变为:

[['0,3', '0,3', '02'], ['43', '5', '3'], ['3', '3,2', '01']]

又好又简单的解决方案+1