This is an example dataset:
df = pd.DataFrame({'Date': ['11-9-2019', '11-9-2020', '11-8-2019', '15-5-2020'],
'name': ['Allen', 'Allen', 'David', 'David'],
'Grade': [50, np.nan, 60, np.nan],
'code': [3352326, np.nan, 22233467, np.nan]})
df['Date'] = pd.to_datetime(df['Date'])
df
What I want to do is to filter the latest date by column 'name' (ex: Allen). However, all info is in the row with the oldest date (ex: Grade, code), the row with the latest date all have missing data. I want the result to only show the rows with the latest date but also want to move the info from the rows with the oldest date to the rows with the latest date. Like the result below.
df1 = pd.DataFrame({'Date': ['11-9-2020', '15-5-2020'],
'name': ['Allen', 'David'],
'Grade': [50, 60],
'code': [3352326, 22233467]})
df1['Date'] = pd.to_datetime(df1['Date'])
df1
I'm not sure if it's possible, and I couldn't find related results. Thanks in advance!