Python read/write CSV file

Source: Internet
Author: User

Blog https://www.cnblogs.com/en-heng/p/5630849.html describes how to use Pandas for data analysis

ImportPandas as PD#any number of groups of listsA = [A.]b= [4,5,6]    #the key value in the dictionary is the column name in the CSVDataframe = PD. DataFrame ({'A_name'A'B_name': b})#storing Dataframe as Csv,index indicates whether the row name is displayed, Default=trueDataframe.to_csv ("Test.csv", index=false,sep=',')
Import= pd.read_csv ('test.csv')
ImportCSV#Python2 can replace open with fileWith open ("Test.csv","W") as Csvfile:writer=Csv.writer (csvfile)#Write Columns_name FirstWriter.writerow (["Index","A_name","B_name"])    #write multiple lines with writerowsWriter.writerows ([[0,1,3],[1,2,3],[2,3,4]])
Import Csvwith Open ("test.csv","R") as CSVFile:     = Csv.reader (csvfile)    # This does not require ReadLines     for Reader:         Print Line

Python read/write CSV file

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.