Let's say I have a similar pandas.DataFrame
:
Date L1 L2 L3 x1 x2 target
0 2020-07-01 0 0 Canada 13 53 1079461752
1 2020-07-01 0 0 US 10 55 3753714491
2 2020-07-01 0 0 Europe 12 55 3070135668
3 2020-07-01 0 1 Canada 13 52 384636447
4 2020-07-01 0 1 US 12 52 7934572515
... ... ... ... ... ... ... ...
2245 2020-07-30 4 3 US 14 53 9352550370
2246 2020-07-30 4 3 Europe 10 50 3589288902
2247 2020-07-30 4 4 Canada 14 55 8793280897
2248 2020-07-30 4 4 US 10 54 9289037195
2249 2020-07-30 4 4 Europe 10 52 2109067647
I want to add a column to the dataframe that will say what was the date where the combination of L1, L2 and L3 first appeared.
I thought about doing df.groupby(by=['L1', 'L2','L3']).Date.min()
and I get the following result:
L1 L2 L3
0 0 Canada 2020-07-01
Europe 2020-07-01
US 2020-07-01
1 Canada 2020-07-01
Europe 2020-07-01
...
4 3 Europe 2020-07-01
US 2020-07-01
4 Canada 2020-07-01
Europe 2020-07-01
US 2020-07-01
but I don't know how to merge the result to the main dataframe. I would greatly appreciate any help. Thanks