R
R
Ruslan Mordovanech2021-12-07 13:53:13
Python
Ruslan Mordovanech, 2021-12-07 13:53:13

How to filter csv data by selected column name?

with open('Список.csv', 'r', encoding='utf-8') as f:
    reader = csv.reader(f, delimiter='\t')

    data = []
    for row in reader:
        data.append({'date':row[0], 'judges':row[1], 'case':row[2],
                     'court_name':row[3], 'court_room':row[4], 'case_involved':row[5], 'case_description':row[6]})

with open('1new_data.json', 'w', encoding='utf-8') as f:
    json.dump(data, f, ensure_ascii=False, indent=7)


Everything works great, but I don't need all the data, how do I filter it so that I get a list that contains only the name of this column 'court_name'?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Mordovanech, 2021-12-07
@Hery1

with open('Список.csv', 'r', encoding='utf-8') as f:
    reader = csv.reader(f, delimiter='\t')

    data = []
    for row in reader:
        if  '       ' in row[3]:
            data.append({'date':row[0], 'judges':row[1], 'case':row[2],
                     'court_name':row[3], 'court_room':row[4], 'case_involved':row[5], 'case_description':row[6]})

with open('1new_data.json', 'w', encoding='utf-8') as f:
    json.dump(data, f, ensure_ascii=False, indent=7)

I came up with something but I need to see the list will not be damaged in the process.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question