I have the following Table
      time                   userid   market   device    query      querytype   browser
0     2020-07-01  04:47:21   A        EN-US    PC        WEATHER    WEATHER     EDGE
1     2020-07-01  07:23:52   C        ZH-CN    MOBILE    RECIPIES   FOOD        SAFARI
2     2020-07-01  15:32:57   D        EN-GB    TABLET    DOGS       ANIMALS     CHROME
3     2020-07-01  17:16:21   A        EN-CA    PC        SEATTLE    CITY        EDGE
4     2020-07-01  21:07:21   D        EN-GB    TABLET    DOG FOOD   ANIMAL      CHROME
5     2020-07-01  22:26:21   E        DE-DE    MOBILE    IPHONE     PRODUCTS    CHROME
And I am trying to get the last query for userid.
  last_query  
0        NaN  
1        NaN 
2        NaN 
3    WEATHER  
4       DOGS
5        NaN
I am using the following code to achieve the problem but I don't get any values.
s = pd.Series()
for name, value in df.groupby('userid'):
    userid = name
    last_query = value['query'].shift()
    s.append(last_query)
Is there any way to combine the values together or to achieve this at all?
 
    