简体   繁体   English

使用 python Z3A43B4F88325D94022C0EFA9C2FA2 库合并连接 2 个具有多个 null 值列的 csv 文件

[英]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.我想对两个 CSV 文件进行连接,以从两个文件中获取唯一值。 For this particular problem, I am using the merge function of pandas lib.对于这个特殊问题,我使用 pandas lib 的合并 function。 the CSV files I am using are having multiple columns and various rows have Null values for certain attributes/columns.我正在使用的 CSV 文件具有多个列,并且各个行具有某些属性/列的 Null 值。 I am trying to use astype('Int32') , but how can I use it for multiple columns at a time.我正在尝试使用astype('Int32') ,但是如何一次将它用于多个列。 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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