-1

I am new to python and scripting in general. so if this seems simple I am sorry. I have tried to google etc but not finding what I am after.

  • Issue I have a excel sheet that I import
import pandas as pd
path_input = r'C:\Users\XXXXX\PycharmProjects\List.xlsx

From this I can then pull and print any column I like for example below

df = pd.read_excel(path_input)
fqdn = list(df.FQDN)
owner = list(df.Owner)

what I would like to do is only call data where cells in column fqdn is equal to a certain name in column owner.

so that I can then use the fqdn data to eventually run code to login to the devices.

Any help is really appreciated.

example would be pulling

    fqdn             owner
abc.example.com      David
cde.example.com      David

Answered - I ended up doing a combination of suggestions but I found this worked for me.

''' new_df = df[df.Owner == 'Name'] new_df1 = new_df.iloc[0:87, 0:1]

1 Answers1

0

What I understood you actually want to call cells in column owner that are equal to a certain name in column owner, not vice versa.

You may not be able to directly call the data that satisfies the condition you want, but you can easily edit the dataframe after calling. So,

new_df = df[df.OWNER == CERTAIN_NAME] 

would return the rows where owner names are equal to a given name.

Nuri Taş
  • 3,828
  • 2
  • 4
  • 22
  • Thank you, I used your suggestion and it worked nearly as I wanted. however I would like to reduce it slightly more My code is currently now from datetime import date from shutil import copyfile import pandas as pd date_backup = date.today() print(date_backup) str_date_backup = str(date_backup) path_input = r'C:\Users\x\Projects\x\List.xlsx' df = pd.read_excel(path_input) first_column = df[df.columns[0]] new_df = df[df.Owner == 'Name'] print(new_df) How do I get it to just pull column 0 instead of the whole sheet. – asthmatic_weasel Aug 05 '22 at 10:40