用python处理csv文件,csv文件中有string格式,我想把csv中的数据输出为一个数组,
发布网友
发布时间:2022-04-15 02:18
我来回答
共2个回答
热心网友
时间:2022-04-15 03:47
使用 python list即可,因为list可以加入不同的数据类型的数据。
results = list()
lines = open('cvs_file', 'r').readlines()
for line in lines:
elements = line.strip().split(',') # supposed limiter is ','
for e in elements:
try:
results.append(float(e))
except:
continue
# Here results will contains all splitted elements
# all elements are string read from cvs file, so you need to
# converse it with float operator. But if element is read string
# we can catch conversion exception and throw it anyway.
追问那请问如何将elements的值输入result中呢
热心网友
时间:2022-04-15 05:05
python的csv模块可用