I have one data frame that outputs hostname and agent_version this is named df_filter output:
hostname agent_version 10 LN07WXDHQ92196 6.16.13008.0 56 LN20WXDHQ58722 6.16.13008.0 61 PC08W7D0811273 6.13.12708.0 100 PC09WXD09003874 6.13.12708.0 128 PC09WXD09003764 6.20.13408.0 155 PC07WXD07024782 6.16.13008.0 162 TB56WXDHQ54910 6.20.13408.0 164 PC12WXD12024954 6.13.12708.0 207 TB07WXD07018788 6.14.12806.0 354 PC10WXD10006757 6.14.12806.0 602 PC59WXDHQ80140 6.14.12806.0
i have another sccm data frame called df_sccm Name
0 Provisioning Device (Provisioning Device) 1 x64 Unknown Computer (x64 Unknown Computer) 2 x86 Unknown Computer (x86 Unknown Computer) 3 PC20WXDHQ60970 4 SV03TMCCMPRI ... ... 27231 LN51WXDHQ57087 27232 LN07WXDHQ098858 27233 LN08WXDHQ100237 27234 LN43WXDHQ100397 27235 PC01WXD03437647
check cs dataframe is in sccm df
#df_sccm_check = df_filter.isin(df_sccm) #print(df_sccm_check)
i am trying to see if my output of the first dataframe is in my second dataframe (df_sccm), when i run it, it just says false, even though there are some machines thare in there
Advertisement
Answer
I am not sure if you can use .isin()
like that. I would probably use a left join like that:
import pandas as pd df_filter = pd.DataFrame( data={ 'hostname': ['PC20WXDHQ60970', 'LN07WXDHQ92196','PC09WXD09003874'], 'agent_version': ['6.16.13008.0', '6.16.12038.0', '6.16.14008.0'] } ) df_sccm = pd.DataFrame( data={'agent_version': ['LN07WXDHQ92196', 'PC01WXD03437647', 'x86 Unknown Computer (x86 Unknown Computer)']} ) df_filter['Check'] = True pd.merge(df_sccm, df_filter[['hostname', 'Check']].rename(columns={'hostname': 'agent_version'}), on=['agent_version'], how='left').fillna(False)
which yields the following data frame:
agent_version Check 0 LN07WXDHQ92196 True 1 PC01WXD03437647 False 2 x86 Unknown Computer (x86 Unknown Computer) False
EDIT
You could try this then:
import pandas as pd from itertools import chain df_filter = pd.DataFrame( data={ 'hostname': ['PC20WXDHQ60970', 'LN07WXDHQ92196','PC09WXD09003874'], 'agent_version': ['6.16.13008.0', '6.16.12038.0', '6.16.14008.0'] } ) df_sccm = pd.DataFrame( data={'agent_version': ['LN07WXDHQ92196', 'PC01WXD03437647', 'x86 Unknown Computer (x86 Unknown Computer)']} ) df_filter.isin(list(chain.from_iterable(df_sccm.values.tolist())))
It relies on the isin()
method and returns:
hostname agent_version 0 False False 1 True False 2 False False
Now, you can get the True rows only by the following line:
df_filter[df_filter.hostname.isin(list(chain.from_iterable(df_sccm.values.tolist())))] ----------------------------------------------- hostname agent_version 1 LN07WXDHQ92196 6.16.12038.0 -----------------------------------------------