简体   繁体   中英

Merge join 2 csv files with multiple null values columns using python pandas librery

I want to do a join on two CSV files to get the unique values out of both files. For this particular problem, I am using the merge function of pandas lib. the CSV files I am using are having multiple columns and various rows have Null values for certain attributes/columns. I am trying to use astype('Int32') , but how can I use it for multiple columns at a time. Do I have to run some loop or is it possible otherwise?

在此处输入图像描述

import pandas as pd

# reading csv files
data1 = pd.read_csv('1.csv')
data2 = pd.read_csv('2.csv')

# using merge function by setting how='right'
output3 = pd.merge(data1, data2,
                on='LOAN_NO',
                how='right')

# displaying result
print(output3)

在此处输入图像描述

import pandas as pd
  
# reading csv files
data1 = pd.read_csv('1.csv')
data2 = pd.read_csv('2.csv')
  
# using merge function by setting how='outer'
output4 = pd.merge(data1, data2, 
                   on='LOAN_NO', 
                   how='outer')
  
# displaying result
print(output4)

在此处输入图像描述

import pandas as pd

# reading two csv files
data1 = pd.read_csv('1.csv')
data2 = pd.read_csv('2.csv')

# using merge function by setting how='inner'
output1 = pd.merge(data1, data2,
                on='LOAN_NO',
                how='inner')

# displaying result
print(output1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM