0

I have a column in my DataFrame which contains values 1, 0, and backorder. I used the strip() method to remove the backorder values in order to get this code to work, but now it won't run with empty cells. Is there a way to just skip over these empty boxes since i don't want them or their surrounding columns to be affected.

My code is attempting to make a new column using the 1s and 0s.

final_dataframe = final_dataframe.applymap(lambda df_value: str(df_value).rstrip('backorder'))
#Removes "backorder" from In stock? column (temporarily)

final_dataframe['In stock?'] = final_dataframe['In stock?'].astype(int)
conditions = [
    (final_dataframe['In stock?'] == 1 & [final_dataframe['qty_total'] < 1]),
    (final_dataframe['In stock?'] == 0 & [final_dataframe['qty_total'] >= 1])
]
t_or_f = ['True', 'False']
final_dataframe['Unlist This']
print(final_dataframe)
3
  • Can you share a reproducible example (just a few rows) of your dataset and the desired output ? Commented Oct 6, 2022 at 21:11
  • welcome to stackoverflow! please review guidelines in posting a reproducible example stackoverflow.com/help/minimal-reproducible-example Commented Oct 6, 2022 at 21:33
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Oct 6, 2022 at 22:40

1 Answer 1

1

With no of example data its difficult to answer. What if you removed the rows that have the "backorder" values. fdf will be final_dataframe. So if is it not equal it is kept.

fdf = fdf[fdf['backorder']!='backorder']

If you like the answer check it as accepted. If it does not provide an example.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.