青春有我
我猜你想要一个具有最大日期值的日期列max(date,date2)df: date age english date2 value0 2020-01-08 29.0 55.0 NaN 51 2020-01-22 22.0 45.0 NaN 02 2020-01-08 29.0 55.0 2020-01-08 53 2020-01-18 43.0 75.0 2020-05-18 84 NaN NaN NaN 2019-02-11 3df['date'] = pd.to_datetime(df['date'])df['date2'] = pd.to_datetime(df['date2'])df['date'] = df[['date','date2']].max(axis=1)df.drop('date2', axis=1, inplace=True)df.fillna(0,axis=1,inplace=True)df: date age english value0 2020-01-08 29.0 55.0 51 2020-01-22 22.0 45.0 02 2020-01-08 29.0 55.0 53 2020-05-18 43.0 75.0 84 2019-02-11 0 0 3 编辑:如果您只想替换为date2如果存在:import numpy as npdf['date'] = pd.to_datetime(df['date'])df['date2'] = pd.to_datetime(df['date2'])df['date'] = np.where(df['date2'].isnull(),df['date'],df['date2'])df.drop('date2', axis=1, inplace=True)df.fillna(0,axis=1,inplace=True)