'Get a line with a unique ID and where the date is greater than a saved value with Pandas

In the code below Iam trying to find rows that have an ID (that aren't empty) and then see if the date attached to those rows are newer than a set date. Then updating that set date at the end.

The main part that is giving me issues is grabbing a specific row where the date is newer than the specified on: df = data_df.loc[data_df['hotelID'] == sqlIDs[neededId] and df.iloc[row, 'approvedAt'] > MostRecent]

global data_df
neededId = 0
messages = []
f = open("MostRecentDate", "r+")
MostRecent = f.read()
dateCheck = False

while neededId < len(sqlIDs):
    if sqlIDs[neededId] > 0:
        channel = newsIds[neededId]
        row = 0
        df = data_df.loc[data_df['hotelID'] == sqlIDs[neededId]]
        if len(df.index) > 0:
            while row < len(df.index):
                df = data_df.loc[data_df['hotelID'] == sqlIDs[neededId] and df.iloc[row, 'approvedAt'] > MostRecent]
                message = newsChannelSender(df.iloc[row])
                sent = [channel, message]
                messages.append(sent)
                for line in fileinput.input(f, inplace=1):
                    line = line.replace(MostRecent, df.iloc[row, 'approvedAt'])
                    sys.stdout.write(line)
                    dateCheck = True

            row = row + 1
    neededId = neededId + 1
if dateCheck is True:
    return messages

return None

'''



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source