I have been trying to search a dataframe for a list of numbers, every time a number matches in a column I would like to return the whole row and save it to a new dataframe, and then to an excel.
millreflist is the list of numbers - can be of random length.
TUCABCP is the dataframe I am searching.
PO is the column I am searching in for the numbers.
I have tried the code below using .loc, but when opening the new excel file I am just getting the header and no rows or data.
millreflistlength = len(millreflist)
for i in range(millreflistlength): TUCABCP = TUCABCP.loc[TUCABCP['PO'] == millreflist[i]]
TUCABCP.to_excel("NEWBCP.xlsx", header=True, index=False)
I have used the following question for reference, but it does not cover when you would like to search with a list of numbers: Selecting rows from a Dataframe based on values in multiple columns in pandas