1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] CSV data not outputting from list comprehension after record count (for loop)...

Discussão em 'Python' iniciado por Stack, Novembro 28, 2025.

  1. Stack

    Stack Membro Participativo

    I've been tasked to manipulate a CSV file in Python. Set up a strip & split command to clean up the data, and it works:

    with open("GLB.Ts+dSST_cleaned.csv") as csv:
    header = next(csv)

    # Format
    data_line = [line.strip().split(",") for line in csv]
    print(data_line[0])


    But when I add a record count above it, the print(dataline) comes back empty. Conversely, if the record count goes below it, the record count doesn't return anything.

    # File Open
    with open("GLB.Ts+dSST_cleaned.csv") as csv:
    header = next(csv)

    # Record Count
    record_count = 0
    for record in csv:
    record_count += 1
    print(record_count)

    # Format
    data_line = [line.strip().split(",") for line in csv]
    print(data_line[0])


    I'm trying not to use the csv module at the moment.

    Specifically, I need a record count to output correctly and the formatting to be able to return record information, instead of outputing as an empty list.

    Continue reading...

Compartilhe esta Página