Convert dataframe column to datetime only if length of string is not zero
问题 I'd like to convert a dataframe column which has a date string. But in some cases, the date string might be empty due to certain conditions. So I just want all the other rows in that column to be converted to datetime format except the rows in that particular column which might be blank. Is it possible? What I've tried so far: Option1: df['etime'] = pd.to_datetime(df['etime'],errors='ignore').dt.strftime('%Y-%m-%d %H:%M') Option 2: for ind in df.index: if (df['etime'].str.len()[ind] == 0) :