I am filtering some data from the csv file which works fine, but while matching a list items via str.conatin
regex in pandas it prints the result for the items which is finds but i want to tag the items which does not match like "kpc8472", "kpc1165"
these are not present in the CSV file thus not returning any results but i need to know about those missing items to be tagged as well.
import pandas as pd
# server names to be searched on the file in list format
search_list = ["kpc2021","kpc8291","kpc8471", "kpc8472", "kpc1165"]
# sorted column list
cols = [ 'Server', 'Server Name', 'iLO FW', 'Firmware', 'Appliance Name']
# Reading CSV with filtered columns
df = pd.read_csv("Server-Inventory.csv", usecols=cols)
# match the search_list items from the column "Server Name"
df = df[df['Server Name'].astype(str).str.contains('|'.join(search_list))]
print(df)
DataFrame:
Server Server Name iLO FW Firmware Appliance Name
0 ENC2002, bay 10 kpc2021 2.50 Sep 23 2016 I36 v2.52 (10/25/2020) OV C7000 enclosures 1
1 ENC8023, bay 7 kpc8291.db.com 2.40 Dec 02 2015 I36 v2.52 (10/25/2020) OV C7000 enclosures 1
2 enc8009, bay 12 kpc8471.db.com 2.61 Jul 27 2018 I42 v1.42 (06/20/2020) OV C7000 enclosures 1
3 enc1011, bay 1 kpc8479 2.55 Aug 16 2017 I36 v2.74 (10/21/2019) OV C7000 enclosures 1
4 enc1014, bay 1 kpc1168 2.70 May 07 2019 I36 v2.74 (11/13/2019) OV C7000 enclosures 1
Result:
Server Server Name iLO FW Firmware Appliance Name
440 ENC2002, bay 10 kpc2021 2.55 Aug 16 2017 I36 v2.52 (10/25/2020) OV C7000 enclosures 1
981 enc8023, bay 7 kpc8291 2.55 Aug 16 2017 I36 v2.52 (10/25/2020) OV C7000 enclosures 2
2642 enc8009, bay 12 kpc8471 1.30 May 31 2018 I42 v1.42 (06/20/2020) ov7003
Thanks for the help and ideas.
Note: I need to tag items of the list search_list
which is not matched!