1
Hello,
I have two files . csv as below:
.csv1
POS,ID
28000167,.
28000263,.
28000484,.
28000711,.
28000728,.
28000885,.
28089922,.
28089927,.
28090173,.
28090325,.
28090326,.
28090331,.
28090415,.
28090467,.
28096247,.
28096264,.
28096284,.
.csv2
POS,ID
28000167,rs75043266
28000263,rs151210258
28000484,rs7175266
28000627,.
28000711,.
28000728,rs140405700
28000885,.
28089732,.
28089847,.
28089876,.
28089898,.
28089922,rs12592271
28089927,rs113937352
28090008,.
28090173,rs12592307
28090325,rs187389297
28090326,rs74005248
28090331,rs113905655
I would like to update the Row[1] values of the . csv1 file with the Row[1] values of the . csv2 file if the Row[0] of . csv1 is present in Row[0] of . csv2.
In this case my file . csv1 would become as:
.csv1
POS,ID
28000167,rs75043266
and so on for all the other iterations he finds...
What I have so far of code is not much since I didn’t get any iteration...
import csv
csv1 = open("arquivo1.csv")
reader1 = csv.reader(csv1, dialect='excel-tab')
csv2 = open("arquivo2.csv")
reader2 = csv.reader(csv2, dialect='excel-tab')
next(reader1, None)
for row1 in reader1:
next(reader2, None)
for row2 in reader2:
Any help would be welcome! Thank you.
Excellent! I understood both methods perfectly! I already know Pandas because I used it in a course of data analysis of Coursera... However I thought it was more used to generate graphics and Plots and I forgot this part of "basic" edition of it! I’ll take a closer look at it, since most of my data analysis files are in csv!!!! Very good! Thank you!!
– guidebortoli
Not at all. Dude, Pandas exists exactly to help with data analysis. I strongly advise its use. Good luck!
– Luiz Vieira