79276899

Date: 2024-12-12 23:57:22
Score: 0.5
Natty:
Report link
# Put 'ok' in status column if it is not 'deleted'. Only in the 1st row as for 'deleted'
df['status'] = np.where((df['name'] != '') & (df['status'] != "deleted"), 'ok', df['status'])
# Fill in status column according to the value on the row above 
df['status'] = df['status'].replace('', np.nan).fillna(method='ffill')

# Remove the rows where the status is 'deleted'
df = df.drop(index=df[df['status'] == 'deleted'].index)
# Remove the rows where there is no region
df = df.drop(index=df[df['region'] == ''].index)
# Rplace the 'ok' status by an empty string as in the original df
df['status'] = df['status'].replace('ok', '')
display(df)

res

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: rehaqds