Skip to content Skip to sidebar Skip to footer

Categorical Assignments Using Pd.apply Based On Multiple Conditions On Pandas Columns

I have a dataframe that contains Item Id numbers with multiple tasks and completion dates for those tasks. I am trying to assign categories based on task completions or in-completi

Solution 1:

Is there a different approach i should take?

Rafaelc offered the correct answer:

Change row['Task 1 Comp Date'].isnull() for pd.isnull(row['Task 1 Comp Date'])

This remedies the "Trouble With NaNs" diagnostic you reported:

AttributeError: ("'Timestamp' object has no attribute 'notnull'", 'occurred at index 8')

The current question that you asked has been answered. Your "use conditional & for another check" remark suggests that perhaps you would like to post a separate question.

Solution 2:

2 years after this question had been asked, I encountered a similar error. I solved it according to the solution of this question, by checking if it was pd.NaT instead of using isnull() or notnull()

Here is how to change the op's example.

defgating(row):
    if row['Task 1 Comp Date'] is pd.NaT:
        return"Pending Task 1"if row['Task 3 Comp Date'] isnot pd.NaT:
        return"Complete"

Post a Comment for "Categorical Assignments Using Pd.apply Based On Multiple Conditions On Pandas Columns"