Good morning,
I'm trying to update a DataFrame based on the contents of two columns and am running into issues.
Specifically, I have a column called IP, another called VISITTIME. I've added two columns called OLDEST and NEWEST which need to contain the min and max VISITTIME for the IP of that row.
Using:
df2 = pd.merge(df.groupby('IP')['VISITTIME'].min().to_frame(),
df.groupby('IP')['VISITTIME'].max().to_frame(), on="IP")
I can get the min and max times for each IP in the table. I can then iterate over that but I don't know how to update the original DataFrame.
Essentially what I'm asking is how do I do the following in pandas:
UPDATE df SET df.OLDEST = df2.OLDEST, df.NEWEST = df2.NEWEST WHERE df.IP=df2.IP;
I feel like this should be easy and I'm ashamed that it isn't.
Thank you