I have a dateframe like this:
import pandas as pd
df = pd.DataFrame({'Car_ID': ['B332', 'B332', 'B332', 'C315', 'C315', 'C315', 'C315', 'C315', 'F310', 'F310'], \
'Date': ['2018-03-15', '2018', '2018-03-12', '2018', '2018-03-16', '2018', \
'2018', '2018-03-11', '2018-03-10', '2018'], \
'Driver': ['Alex', 'Alex', 'Alex', 'Sara', 'Sara', 'Sara', 'Sara', 'Sara', 'Franck','Franck']})
df
Out:
Car_ID Date Driver
0 B332 2018-03-15 Alex
1 B332 2018 Alex
2 B332 2018-03-12 Alex
3 C315 2018 Sara
4 C315 2018-03-16 Sara
5 C315 2018 Sara
6 C315 2018 Sara
7 C315 2018-03-11 Sara
8 F310 2018-03-10 Franck
9 F310 2018 Franck
Which contain some incorrect date? For this reason I want to create two new columns like this:
Car_ID Date D_Min D_Max Driver
0 B332 2018-03-15 2018-03-15 2018-03-15 Alex
1 B332 2018 2018-03-12 2018-03-15 Alex
2 B332 2018-03-12 2018-03-12 2018-03-12 Alex
3 C315 2018 2018-03-16 2018 Sara
4 C315 2018-03-16 2018-03-16 2018-03-16 Sara
5 C315 2018 2018-03-11 2018-03-16 Sara
6 C315 2018 2018-03-11 2018-03-16 Sara
7 C315 2018-03-11 2018-03-11 2018-03-11 Sara
8 F310 2018-03-10 2018-03-10 2018-03-10 Franck
9 F310 2018 2018 2018-03-10 Franck
For D_Min For incorrect dates I want to take the date before which is right. If there the date before is not correct I'll take as it is, like the example 9 F310 2018 2018 2018-03-10 Franck.
And I want to do the same for D_Max. But if the date is correct the D_Min and D_Max should be the same.
Thanks for your advices.