How do I remove data after a comma within a column of a dataframe using pandas?

Question:

I have a dataframe which has the below columns

df3
    Deposit Name Initial Date 
    22      Gu    03/22/2007 0:00
    30       Pa   09/30/2009 0:00
    11       Ch   1/15/22, 5/11/21

the problem is for row 3, I want the initial date only before the comma seperated. So my final df should not have " , 5/11/21".

Im able to manually do this by

df3.at[3,'Initial Date']= "1/15/22"

But I want a permanent solution so that if there is ever an occurrence in the future where there are more than 1 date under Initiate Date column, then pandas only stores the first date before the comma. How do I do this?

Asked By: Jay Janardhan

||

Answers:

df3['Initial Date'].replace(",.*", "", regex=True, inplace=True)
Answered By: MoRe
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.