S
S
shmostertoster2016-11-15 00:08:07
Python
shmostertoster, 2016-11-15 00:08:07

How to get only full matches with query from csv?

Good afternoon!
Here is the code:

import csv

with open('test.csv', mode='r') as f:
    reader = csv.reader(f)
    for num, row in enumerate(reader):
        day = str(200)
        if day in row[0]:
                a = row[0].count("P")
                print(row[0], " --- ", a)

I only need rows with the number "200". But I get everything where there is a figure "200".
I've tried using regex but it doesn't work.
200;O;O;P;P;O;O;P;P;O;O;O;O;P;P;O;O;P;P;O;O;O  ---  8
200;P;P;O;O;P;P;O;O;P;P;P;P;O;O;P;P;O;O;P;P;P  ---  13
2200;O;O;P;P;O;O;P;P;O;O;O;O;P;P;O;O;P;P;O;O;O  ---  8
11200;O;O;P;P;O;O;P;P;O;O;O;O;P;P;O;O;P;P;O;O;O  ---  8
57200;P;P;O;O;P;P;O;O;P;P;P;P;P;O;P;P;O;O;P;P;P  ---  14
7720077;O;O;P;P;O;O;P;P;O;O;O;O;P;P;O;O;P;P;O;O;O  ---  8
12005;P;P;O;O;P;P;O;O;P;P;P;P;O;O;P;P;O;O;P;P;P  ---  13

Tell me how to get only the rows I need?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2016-11-15
@shmostertoster

if you treat strabismus through the anus, then
if you solve the problem:

with open('test.csv') as f:
    a=f.readlines()

b=[x for x in a if x.startswith('200;')]
print(b)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question