Pandas: comparing information in DataFrame

2

I have 2 DataFrames imported from CSV

CSV1

4616; CCIVIL_03/decreto/2003/D4616.htm
4617; CCIVIL_03/decreto/2003/D4617.htm
4618; CCIVIL_03/decreto/2003/D4618.htm
4619; CCIVIL_03/decreto/2003/D4619.htm
4620; CCIVIL_03/decreto/2003/D4620.htm
4620impressao; CCIVIL_03/decreto/2003/D4620impressao.htm
4621; CCIVIL_03/decreto/2003/D4621.htm
4622; CCIVIL_03/decreto/2003/D4622.htm
4623; CCIVIL_03/decreto/2003/D4623.htm
4624; CCIVIL_03/decreto/2003/D4624.htm
4625; CCIVIL_03/decreto/2003/D4625.htm

CSV2

04456; 2002; CCIVIL_03/Atos/decretos/2002/D04456.html
05931; 2006; CCIVIL_03/Atos/decretos/2006/D05931.html
05940; 2006; CCIVIL_03/Atos/decretos/2006/D05940.html
05922; 2006; CCIVIL_03/Atos/decretos/2006/D05922.html
05933; 2006; CCIVIL_03/Atos/decretos/2006/D05933.html
05934; 2006; CCIVIL_03/Atos/decretos/2006/D05934.html
05937; 2006; CCIVIL_03/Atos/decretos/2006/D05937.html
05921; 2006; CCIVIL_03/Atos/decretos/2006/D05921.html
05932; 2006; CCIVIL_03/Atos/decretos/2006/D05932.html

Follow the implemented code:

import pandas as pd
df_acervo1 = pd.read_csv('../atos_publicados_dec_url_num.csv', sep=';', names=['num', 'url'])
df_acervo3 = pd.read_csv('../atos_publicados_dec_sican_url_num_ano.csv', sep=';',
                         names=['num', 'ano', 'url'])

How can I associate the two CSVs, where there is number matching? in this way:

num, ano, url_CSV1, url_CSV2
2204, 1985, CCIVIL_03/decreto/1851-1899/D02204.html,  CCIVIL_03/Atos/decretos/1895/D02204.html
    
asked by anonymous 06.06.2018 / 19:15

1 answer

2

Brito, in this case you can use the Pandas function - Merge

The code should be:

df_join = pd.merge(df_acervo1, df_acervo3, how ='inner', on = ['num'])

Obs. The ON parameter above represents the key between the two columns

Obs2. In the HOW parameter you will have to put the type of join you want in the same way as in the database (RIGHT, LEFT, INNER)

    
06.06.2018 / 22:42