简体   繁体   English

使用 Pycharm 读取 csv 文件中的特定列

[英]Read specific column in csv file using Pycharm

import csv
with open("bbkp.csv", "r") as csv_file:
    csv_reader = csv.reader(csv_file, delimeter=',')
    line_count = 0
    for row in csv_reader:
        if line_count == 0:
            print(f'Column names are {",".join(row)}')
            line_count += 1
        else:
            print(f'\t{row[0]}latitude {row[1]}longitude {row[2]}.')
            line_count += 1
        print(f'Result {line_count}lines.')
    for lines in csv_reader:
        print(lines[1])

the error show错误显示

Traceback (most recent call last): File "E:/PSM/source code/gile.py", line 8, in csv_reader = csv.reader(csv_file, delimeter=',') TypeError: 'delimeter' is an invalid keyword argument for this function回溯(最后一次调用):文件“E:/PSM/source code/gile.py”,第 8 行,在 csv_reader = csv.reader(csv_file, delimeter=',') TypeError: 'delimeter' is an invalid keyword此 function 的参数

You can try你可以试试
csv_reader = csv.reader(csv_file)
the delimiter of csv reader is ',' by default so you don't need to specify it. csv阅读器的分隔符默认为',',所以你不需要指定它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM