in an excel file, check column 'software in fs' for a string in list 'sheet'. once found, store the data in column in python

To read an excel file and do operations on it, we could use pandas library.

main.py
  import pandas as pd

  # read the excel file
  df = pd.read_excel('filename.xlsx')

  #create a list of software strings to look for corresponding to the 'sheet' list
  software_list = ['software_string1', 'software_string2', 'software_string3']

  #loop through your target column to search for the string
  for idx, row in df.iterrows():
      if row['software in fs'] in software_list:
          #store the data in your desired column
          df.at[idx, 'desired_column'] = row['software in fs']
  
  #write the updated dataframe with desired_column
  df.to_excel('filename.xlsx', index = False)
603 chars
17 lines

In the above code, we read an excel file using pandas and then create a list of software strings to look for. We then loop through the target column 'software in fs' and check if each value is present in our software_list. If it is, we store the data in our desired column. Once we have our updated dataframe, we can write it back to an excel file.

related categories

gistlibby LogSnag