Last active
March 19, 2018 07:22
-
-
Save Everfighting/440ecd33fa3a1ec55a93fe8280ec097b to your computer and use it in GitHub Desktop.
write line with csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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