I have a dataframe like this:
df = pd.DataFrame({"CLASS":["A","A","B"],
"ACTION 1":[np.nan, "01-01-2022", np.nan],
"ACTION 2":["01-04-2022", np.nan, "01-12-2022"]})
df["ACTION 1"] = pd.to_datetime(df["ACTION 1"])
df["ACTION 2"] = pd.to_datetime(df["ACTION 2"])
df
Out[10]:
CLASS ACTION 1 ACTION 2
0 A NaT 2022-01-04
1 A 2022-01-01 NaT
2 B NaT 2022-01-12
I would like to concat/aggregate these rows by the same value in column CLASS as filter, with the dates replacing the NaT values like this:
CLASS ACTION 1 ACTION 2
0 A 2022-01-01 2022-01-04
1 B NaT 2022-01-12
Anyone could help me?