python - how to get values in csv to a report

Trying to get a report from a csv file.

csv file: servers.csv
name,date,zone
server1,3/3/2016,dmz
server2,4/3/2017,prod
server3,4/4/2017,nonprod
server4,6/6/2017,prod

I'm trying to get a list of prod servers that contains the server name and zone.
LVL 1
LN41Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Try ingesting data in your python script using this pipeline...

cat servers.csv | grep -v ^name | grep ",prod"

Open in new window

0
aikimarkCommented:
import csv

f = file('c:\users\mark\downloads\Q_29075243.csv')
for l in csv.reader(f):
    print l[0],l[2]

Open in new window

Produces:
name zone
server1 dmz
server2 prod
server3 nonprod
server4 prod

Open in new window

0
LN41Author Commented:
Hi aikimark,Your answer is helpful but looking for a way to filter only for prod servers rather than manually id them. ideal result produces:

name zone
server2 prod
server4 prod
0
LN41Author Commented:
I think I got it. Thanks for the help.

import csv
with open('servers.csv', newline='') as f:
    reader = csv.reader(f)
    for row in reader:
        if row[3] == 'prod':
            print(row[1],row[3])
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LN41Author Commented:
figured it out myself
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.