简体   繁体   English

Python csv模块读取特定行

[英]Python csv module to read specific line

My current code prints the column that has integers, but some responses have appeared and i need them to be in column 6.我当前的代码打印具有整数的列,但出现了一些响应,我需要它们位于第 6 列。

import csv

with open('WEATHER_1113.txt', 'r') as csv_file:
    csv_reader = csv.reader(csv_file, delimiter=',')

    with open('right_format.csv', 'w') as new_file:
        #csv_writer = csv.writer(new_file)

    for line in csv_reader:
        print(line[5])
import csv

with open('WEATHER_1113.txt', 'r') as csv_file:
    csv_reader = csv.reader(csv_file, delimiter=',')
    for line in csv_reader:
        if line[5][1] == '.':
            print(line[5])

that's should give you the expected output since your data not matching together in number of columns !那应该给您预期的 output 因为您的数据在列数上不匹配!

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

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