There is a quiz script that gives a bonus to the fastest respondents and then 1 point for any correct answer in the timeframe. After a recent update for the newest pandas library the part that applies 1 point to all respondents no longer works. This is a partial segment of the code for it.
if len(repHolder) > 0:
repHolder.columns = ['name', 'points', 'time']
repHolder = repHolder.sort_values('time').reset_index(drop=True)
repHolder.loc[:, 'time'] = repHolder.loc[:, 'time'].apply(
lambda x: (datetime.utcfromtimestamp(x) + timedelta(hours=-4)).strftime("%I:%M:%S %p"))
# Take the first response per participant
minDate = repHolder.groupby('name').min()['time'].reset_index()
repHolder = repHolder.merge(minDate)
# For ties, score by time not by name
timeHolder = repHolder.loc[repHolder['points'], ['time']].drop_duplicates().reset_index(drop=True)
timeHolder['points'] = 0
corHolder = 0
for idx3, row in enumerate(timeHolder.iterrows()):
if corHolder == 0:
timeHolder.loc[idx3, 'points'] = 1
corHolder = 1
elif corHolder == 1:
timeHolder.loc[idx3, 'points'] = 1
corHolder = 2
elif corHolder == 2:
timeHolder.loc[idx3, 'points'] = 1
corHolder = 3
else:
timeHolder.loc[idx3, 'points'] = 1
repHolder = repHolder.merge(timeHolder, on='time', how='left')
repHolder['points'] = (repHolder['points_x'] * repHolder['points_y'])
repHolder.loc[repHolder['points'].isnull(), 'points'] = 0
print('scored winners')
repHolder = repHolder.sort_values('points', ascending=False)
repHolder['qTime'] = (datetime.utcfromtimestamp(qCom.created_utc) + timedelta(hours=-4)).strftime(
"%I:%M:%S %p")
repHolder['deltaTime'] = pd.to_datetime(repHolder['time']) - pd.to_datetime(repHolder['qTime'])
repHolder['points'] = repHolder['points'] + repHolder[['deltaTime', 'points']]. \
apply(lambda x: 1 if (x['deltaTime'].seconds <= 30) and (x['points'] == 1) else 0, axis=1)
print(repHolder)
winHolder = pd.concat([winHolder, repHolder])
Updated pandas code from this:
if not reply.author == None and not reply.banned_by:
repTab = pd.DataFrame([[reply.author.name, gottem, reply.created_utc]])
repHolder = repHolder.append(repTab)
to this:
if not reply.author == None and not reply.banned_by:
repTab = pd.DataFrame([[reply.author.name, gottem, reply.created_utc]])
repHolder = pd.concat([repTab])
post update which got the code to run again but then the code stopped holding all the responses
The
appendmethod has been deprecated in pandas 2. The alternativepd.concatfunction requires a list of dataframes to concatenate, so you need to pass in the original dataframe.Try: