Turn 2010 Q1 to datetime as 2010-3-31

后端 未结 3 811
南旧
南旧 2021-01-24 13:44

How to find a smart solution to turn Year_Q to datetime? I tried to use

pd.to_datetime(working_visa_nationality[\'Year_Q\'])

but got

3条回答
  •  暖寄归人
    2021-01-24 14:20

    My solution with regex.

    df['Year_Q'] = pd.to_datetime(df['Year_Q'].str.replace(r'\ [Q1]+', '-3-31'))
    

提交回复
热议问题