Python reads multiple rows of data from a CVS file

Source: Internet
Author: User

Sometimes we need to read multiple rows and columns of data.

Def Duqu ():
Yiyuan = open (' Yiyuan_id2.csv ', ' R ')
lines = Yiyuan.readlines ()
Yiyuan.close ()

For line in lines:
id = line.split (', ') [0]
Name = Line.split (', ') [1]
Print (Id,name)
Duqu ()

1. Define Read function
2, define the variable Yiyuan, open the file in a read-only way
3. Define variable lines and assign value to lines by reading multiple rows of data
4. Close the file
5, use for loop, every time to read the data
6. Use the Slice method (split) to read the first column of data
7. Use the Slice method (split) to read the second column of data
8. Output read Data
9. Call the Duqu function

Python reads multiple rows of data from a CVS file

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.