[Python] Pandas read_csv does not get the last line in the CSV in python

Discussão em 'Python' iniciado por Stack, Março 12, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to get all the data from a csv and break it down into columns using pandas read_csv

    My code to read the csv is below. The purpose is to get the values for each column and store it in a variable (list).

    df = pd.read_csv(file)
    test_type = df['test_type']
    tps = df['tps']
    mtt = df['mtt']
    mem = df['mem']
    cpu = df['cpu']


    The CSV input file looks like this.

    test_type,tps,mtt,mem,cpu
    500_dr,255.240773286,934.362745167,22.5013831649,8.32771344429
    1000_dr,212.425359712,2278.33653777,33.0718045361,6.50930517338
    1500_dr,212.425359712,2278.33653777,33.0718045361,6.50930517338


    I tried printing the list to see if I have captured the correct values by inserting this in my code.

    print test_type


    Output:

    0 500_dr
    1 1000_dr
    Name: test_type, dtype: object


    It looks like it captures the values just fine except that the last row is not included when I print. How do I fix the code so that it captures the last row as well?

    Continue reading...

Compartilhe esta Página