C
C
CreativeStory2018-05-27 15:55:16
Python
CreativeStory, 2018-05-27 15:55:16

How to compare csv in python?

Good afternoon!
There are 2 csv files with different content.
First
___________
id, prod_name
1, apple
2, cherry
Second
___________
id, src
1, link_1
5, link_5
Please tell me how to match by id and add link if id matches
For example, the result should be:
id, prod_name , src
1, apple, link_1

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
longclaps, 2018-05-27
@CreativeStory

from csv import reader

d = dict(reader(open('Первый.csv')))
for id, src in (reader(open('Второй.csv'))):
    if id in d:
        print(id, d[id], src)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question