I have a dataframe, and for every unqiue ID, make the first 'Diff' column NaT, for example my data starts off looking like
index DEVICE_ID DIFF
0 12 Nat
1 12 20
2 12 30
3 13 40
4 13 40
5 13 21
6 14 9
7 14 10
But I want the resulting dataframe to look like the one below
index DEVICE_ID DIFF
0 12 Nat
1 12 20
2 12 30
3 13 Nat
4 13 40
5 13 21
6 14 Nat
7 14 10
Sorry for the poorly worded question
Using df.duplicated() and df.loc
df.loc[~df.DEVICE_ID.duplicated(),'DIFF'] = pd.NaT
>>df
index DEVICE_ID DIFF
0 0 12 NaT
1 1 12 20
2 2 12 30
3 3 13 NaT
4 4 13 40
5 5 13 21
6 6 14 NaT
7 7 14 10
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With