简体   繁体   English

如何将列表写入没有括号的csv列中?

[英]how to write list into csv columns without brackets?

I want to make a csv, where each row contains certain "single" variables (photo_paths[i], i, p, norm_ratio) and then many columns of list items (point_values). 我想制作一个csv,其中每一行都包含某些“单个”变量(photo_paths [i],i,p,norm_ratio),然后是列表项的许多列(point_values)。

face_writer = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
face_writer.writerow([photo_paths[i], i, p, norm_ratio, point_values])

the resulting first and last items in the list contain brackets and a vertical bar: 列表中产生的第一项和最后一项包含方括号和竖线:

|[20.426487199475673
 5986.817702828149]|

all the others in the middle are fine. 中间的所有其他人都很好。

how do I get rid of those symbols? 如何摆脱这些符号?

The argument to writerow() should be a 1-dimensional list of all the fields. writerow()的参数应该是所有字段的一维列表。 point_values is a list, and you're nesting it inside the list. point_values是一个列表,您将其嵌套在列表中。 You shold concatenate it instead: 您将其串联起来:

face_writer.writerow([photo_paths[i], i, p, norm_ratio] + point_values)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM