美文网首页
Python读取csv

Python读取csv

作者: 陶_306c | 来源:发表于2021-04-12 17:37 被阅读0次

    获取每一行

    import csv
    file = 'C:/Users/zyx/Desktop/blog.csv'
    with open(file,'r',encoding='ISO-8859-1')as f:
        reader = csv.reader(f)
    
        for row in reader:
            row = str(row)
            print(row)
    

    获取某一行

    with open('data.csv', 'r') as f:
    3     reader = csv.reader(f)
    4     result = list(reader)
    5     print(result[1])
    

    获取某一列

    with open('data.csv', 'r') as f:
    3     reader = csv.reader(f)
    4     for i in reader:
    5         print(i[0])
    

    相关文章

      网友评论

          本文标题:Python读取csv

          本文链接:https://www.haomeiwen.com/subject/afwxlltx.html