I have a dataframe with the following information:
Initial_Date | First_Revision_Date | Second_Revision_Date |
---|---|---|
1/1/2022 | ||
1/1/2022 | 2/15/2022 | 5/4/2022 |
3/19/2024 | 6/2/2024 |
I want to add a column called Final Date, which is the maximum value of the three columns, and where a column is null I want it to be ignored.
I have tried the following code to add a column:
df['Initial_Date']=pd.to_datetime(df['Initial_Date'],errors='coerce')
df['First_Revision_Date']=pd.to_datetime(df['First_Revision_Date'],errors='coerce')
df['Second_Revision_Date']=pd.to_datetime(df['Second_Revision_Date'],errors='coerce')
df.insert(len(df.columns),'Final_Date',allow_duplicates = False, value=df['Initial_Date','First_Revision_Date','Second_Revision_Date'].max(axis=1))
Error:
3801 # InvalidIndexError. Otherwise we fall through and re-raise
3802 # the TypeError.
3803 self._check_indexing_error(key)
New contributor
user23237706 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2