Skip to content

Instantly share code, notes, and snippets.

@Everfighting
Last active March 19, 2018 07:22
Show Gist options
  • Save Everfighting/440ecd33fa3a1ec55a93fe8280ec097b to your computer and use it in GitHub Desktop.
Save Everfighting/440ecd33fa3a1ec55a93fe8280ec097b to your computer and use it in GitHub Desktop.
write line with csv
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)
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"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment