简体   繁体   English

匹配 2 个不同的 dataframe 但长度不同的列值

[英]Match column values of 2 different dataframe but of different length

检查数据集图像

I have TOTAL 2 dataset where dataset1 has PATIENTID column of around 40 entries and another dataset2 has Same PATIENTID of around 700 entries我有 TOTAL 2 个数据集,其中 dataset1 具有大约 40 个条目的 PATIENTID 列,另一个 dataset2 具有大约 700 个条目的相同 PATIENTID

I want to check if the PATIENTID of dataset1 are present in dataset2 or not.我想检查 dataset1 的 PATIENTID 是否存在于 dataset2 中。

I tried in Python Jupyter notebook, it is not working though through Python code.我在 Python Jupyter 笔记本中尝试过,但通过 Python 代码无法正常工作。

PatientsNotTreated=unique(Datase1.PatientID)[!unique(Dataset1.PatientID) in unique(Dataset2.PatientID)]
PatientsNotTreated

I am getting error:我收到错误:

PatientsNotTreated=unique(Datase1.PatientID)[!unique(Dataset1.PatientID) in unique(Dataset2.PatientID)]
                                                     ^
    SyntaxError: invalid syntax

I expect output of patientID which are not present in daTASET2我预计 daTASET2 中不存在的患者 ID 的 output

Use Series.isin to make a boolena indexing with DataFrame.loc .使用Series.isinDataFrame.loc进行布尔索引 Finally use Series.unique :最后使用Series.unique

arr_out=Dataset1.loc[~Dataset1['PatientID'].isin(Dataset2['PatientID']),'PatientID'].unique()

arr_in=Dataset1.loc[Dataset1['PatientID'].isin(Dataset2['PatientID']),'PatientID'].unique()

to filter dataset1 according to the patient use:根据患者使用过滤 dataset1:

Dataset1_filtered=Dataset1.loc[~Dataset1['PatientID'].isin(Dataset2['PatientID'])]

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

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