Everfighting
3/19/2018 - 6:53 AM

write line with csv

write line with csv

import pandas as pd 
rows = [[1,2,3,4],[2,3,4,1],[3,4,5,2],[1,2,3,4],[1,2,3,4],[1,2,3,4]]
df = pd.DataFrame(rows,columns =["l","t","r","b"])
df.to_csv("test.csv",index=False,sep=',',header=["l","t","r","b"])
import csv
row1  = [1,2,3,4,5]
row2 = [1,2,3,4,5]
row3 = [1,2,3,4,5]
rows = [row1,row2,row3]

with open(csv_name,"w") as csvfile:
    writer = csv.writer(csvfile)
    #先写入columns_name
     writer.writerow(["bottom", "left", "right", "top", "value"])
     #写入多行用writerows
     writer.writerows(rows)