I have one data frame that outputs hostname and agent_version this is named df_filter output:
JavaScript
x
13
13
1
hostname agent_version
2
10 LN07WXDHQ92196 6.16.13008.0
3
56 LN20WXDHQ58722 6.16.13008.0
4
61 PC08W7D0811273 6.13.12708.0
5
100 PC09WXD09003874 6.13.12708.0
6
128 PC09WXD09003764 6.20.13408.0
7
155 PC07WXD07024782 6.16.13008.0
8
162 TB56WXDHQ54910 6.20.13408.0
9
164 PC12WXD12024954 6.13.12708.0
10
207 TB07WXD07018788 6.14.12806.0
11
354 PC10WXD10006757 6.14.12806.0
12
602 PC59WXDHQ80140 6.14.12806.0
13
i have another sccm data frame called df_sccm Name
JavaScript
1
12
12
1
0 Provisioning Device (Provisioning Device)
2
1 x64 Unknown Computer (x64 Unknown Computer)
3
2 x86 Unknown Computer (x86 Unknown Computer)
4
3 PC20WXDHQ60970
5
4 SV03TMCCMPRI
6
7
27231 LN51WXDHQ57087
8
27232 LN07WXDHQ098858
9
27233 LN08WXDHQ100237
10
27234 LN43WXDHQ100397
11
27235 PC01WXD03437647
12
check cs dataframe is in sccm df
JavaScript
1
3
1
#df_sccm_check = df_filter.isin(df_sccm)
2
#print(df_sccm_check)
3
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:
JavaScript
1
15
15
1
import pandas as pd
2
3
df_filter = pd.DataFrame(
4
data={
5
'hostname': ['PC20WXDHQ60970', 'LN07WXDHQ92196','PC09WXD09003874'],
6
'agent_version': ['6.16.13008.0', '6.16.12038.0', '6.16.14008.0']
7
}
8
)
9
df_sccm = pd.DataFrame(
10
data={'agent_version': ['LN07WXDHQ92196', 'PC01WXD03437647', 'x86 Unknown Computer (x86 Unknown Computer)']}
11
)
12
df_filter['Check'] = True
13
pd.merge(df_sccm, df_filter[['hostname', 'Check']].rename(columns={'hostname': 'agent_version'}), on=['agent_version'], how='left').fillna(False)
14
15
which yields the following data frame:
JavaScript
1
5
1
agent_version Check
2
0 LN07WXDHQ92196 True
3
1 PC01WXD03437647 False
4
2 x86 Unknown Computer (x86 Unknown Computer) False
5
EDIT
You could try this then:
JavaScript
1
15
15
1
import pandas as pd
2
from itertools import chain
3
4
df_filter = pd.DataFrame(
5
data={
6
'hostname': ['PC20WXDHQ60970', 'LN07WXDHQ92196','PC09WXD09003874'],
7
'agent_version': ['6.16.13008.0', '6.16.12038.0', '6.16.14008.0']
8
}
9
)
10
df_sccm = pd.DataFrame(
11
data={'agent_version': ['LN07WXDHQ92196', 'PC01WXD03437647', 'x86 Unknown Computer (x86 Unknown Computer)']}
12
)
13
14
df_filter.isin(list(chain.from_iterable(df_sccm.values.tolist())))
15
It relies on the isin()
method and returns:
JavaScript
1
5
1
hostname agent_version
2
0 False False
3
1 True False
4
2 False False
5
Now, you can get the True rows only by the following line:
JavaScript
1
8
1
df_filter[df_filter.hostname.isin(list(chain.from_iterable(df_sccm.values.tolist())))]
2
3
-----------------------------------------------
4
hostname agent_version
5
1 LN07WXDHQ92196 6.16.12038.0
6
-----------------------------------------------
7
8