0

I have a CSV file with 60 different server names, but how do I save all the server names to a list and make a loop that checks if every servername is in the list? Lets say tommorow I compare with a similar CSV file, but it only contains 50 server names. I want it to spit out the servers missing in a print operation how can I do that?

Here is my current code - It reads the CSV file and prints all the server names with an index from 0-59.

csv_file = 'C:\Users\admin\Desktop\csvfolder/some_file.csv'
df = pd.read_csv(csv_file, delimiter=';', skiprows=0, low_memory=False)
print(df)

1 Answer 1

1

What you need to do is to use python set.

See below:

yesterday_servers = {'s1','s3','s8'}
today_servers = {'s1','s8','s19'}

new_servers = today_servers - yesterday_servers
missing_servers  = yesterday_servers - today_servers
print(f' missing {missing_servers}')
print(f' new {new_servers}')

output

 missing {'s3'}
 new {'s19'}
Sign up to request clarification or add additional context in comments.

5 Comments

Oh that's great thanks I'll manually add yesterday_servers list with all the 60 server names, but how do I automatically add the servers to today_servers from the pandas csv reader? @balderman
@Farzadmirzaii Why do you need pandas here?
I download a new csv each day and I want it to compare the servers each day to make print an error if a server suddenly is missing - that's why I need pandas to compare every day with a new downloaded csv file to make sure all 60 servers is still there.
The code that I have posted will do the "diff" for you - no need for pandas.
today_servers does not take servernames from the csv file so

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.