How to make a Marj 2 csv files in Python?

Does anyone have the experience of 2 or 3 different csv files to make one. The point is that the files in the second column is the id field. It is for this field need to do proarco whether there are other files in the same ajtishniki and if Yes, then you can track down these rows with all other columns.

For example, the first csv file

Id A B D F
0 1 2 0 3 1
1 1 2 1 3 1
2 3 3 2 3 1

The second csv file

Id A B D F
0 3 3 2 3 1
1 1 2 3 3 1
2 3 3 4 3 1

It turns out that in the first file line 2 with id = 2, the same as in the second row 0 with id = 2.

I need to get rows with the same id in a separate csv file and get value from all the other columns

Id A B D F
0 3 3 2 3 1

I'm new to Python and in General in Japanese. Got pandas.

import sys
import pandas as pd
from pandas import read_csv
from pandas import merge

df1 = read_csv(sys.argv[1], usecols=[1], header=None)
df2 = read_csv(sys.argv[2], usecols=[1], header=None)


But then, assigning variables to the files I go.

The interface will be like this

python3 script.py file1.csv file2.csv

Maybe there are knowledgeable people who can suggest something
June 16th 19 at 20:21
2 answers
June 16th 19 at 20:23
Maybe there are knowledgeable people who can suggest something

To learn the language.
To read the documentation, there are examples of compared data.
Google examples of solutions of such model problems. Here's an example:
import sys
from StringIO import StringIO
import pandas as pd

TESTDATA=StringIO("""DOB;First;Last
2016-07-26;John;smith
2016-07-27;Mathew;George
2016-07-28;Aryan;Singh
2016-07-29;Ella;Gayau
""")

list1 = pd.read_csv(TESTDATA, sep=";")

TESTDATA=StringIO("""Date of Birth;Patient First Name;Patient Last Name
2016-07-26;John;smith
2016-07-27;Mathew;XXX
2016-07-28;Aryan;Singh
2016-07-20;Ella;Gayau
""")


list2 = pd.read_csv(TESTDATA, sep=";")

print list2
print list1

common = pd.merge(list1, list2, how='left', left_on=['Last', 'First', 'DOB'], right_on=['Patient Last Name', 'Patient First Name', 'Date of Birth']).dropna()
print common
I have done so now, but for some reason Maritsa only the table headers

import sys
import pandas as pd
from pandas import read_csv
from pandas import merge

df1 = read_csv(sys.argv[1])
df1 = df1.dropna(axis=1)
df2 = read_csv(sys.argv[2])
f2 = df2.dropna(axis=1)

merged = df1.merge(df2)
is merged.to_csv("result.csv")
- Rachel89 commented on June 16th 19 at 20:26
and displays normal on the old seal after removing empty block (dropna)? - abigail36 commented on June 16th 19 at 20:29
Yes. removes all the unnecessary and leaves the column with the desired information.

Understand why does not display the old. We must not merit, and do the concatenation.
merged = pd.concat([df1, df2], axis=1, join_axes=[df1]) - Rachel89 commented on June 16th 19 at 20:32
To smiriti 2 file 1 I did it, but how to search for coincidences I something was not cut. Complex - Rachel89 commented on June 16th 19 at 20:35
,

I think he did
import sys
import pandas as pd
from pandas import read_csv
from pandas import merge

df1 = read_csv(sys.argv[1])
#df1 = df1.dropna(axis=1)
df2 = read_csv(sys.argv[2])
#f2 = df2.dropna(axis=1)

frames = [df1, df2]

#result = pd.concat(frames, keys=['x', 'y', 'z'])
result = pd.concat(frames, join='inner', axis=1)
result.to_csv("result.csv")
- Rachel89 commented on June 16th 19 at 20:38
June 16th 19 at 20:25
0. Why pandas in the library Python has a csv module.
1. Both files are read in dictionaries, the key id, the rest of the list in importance.
2. Cross the plurality of keys of the two dictionaries.
3. and at this intersection construct a sample by combining the lists.
I need to do it in pandas. - Rachel89 commented on June 16th 19 at 20:28
can on pandas, and that from the standard library of Python nothing is impossible to use, or what?
Yes, if you really are a beginner then here here (sections 2,3) a short but succinct instructions for working with lists and dictionaries. - abigail36 commented on June 16th 19 at 20:31
Well no, of course, you can use, but you have to do the merge using pandas - Rachel89 commented on June 16th 19 at 20:34

Find more questions by tags PythonCSV