[Python] Python CSV File - Want to filter specific rows/columns

Discussão em 'Python' iniciado por Stack, Maio 27, 2025.

  1. Stack

    Stack Membro Participativo

    I'm new to Python and I'm trying to analyse this CSV file. It has a lot of different countries (as an example below).

    country iso2 iso3 iso_numeric g_whoregion year e_pop_num e_inc_100k e_inc_100k_lo
    Afghanistan AF AFG 4 EMR 2000 20093756 190 123
    American Samoa AS ASM 16 WPR 2003 59117 5.8 5 6.7 3 3 4
    Gambia GM GMB 270 AFR 2010 1692149 178 115 254 3000 1900 4300


    I want to try and obtain only specific data, so only specific countries and only specific columns (like "e_pop_numb"). How would I go about doing that?

    The only basic code I have is:

    import csv
    import itertools

    f = csv.reader(open('TB_burden_countries_2018-03-06.csv'))

    for row in itertools.islice(f, 0, 10):
    print (row)


    Which just lets me choose specific rows I want, but not necessarily the country I want to look at, or the specific columns I want.

    IF you can help me or provide me a guide so I can do my own learning, I'd very much appreciate that! Thank you.

    Continue reading...

Compartilhe esta Página