WALMART Interview Question

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ก.พ. 2025
  • Link of the Question : platform.strat...
    #latest #walmart #interview #question #stratscratch #platform
    Identify users who started a session and placed an order on the same day. For these users, calculate the total number of orders and the total order value for that day.
    Your output should include the user, the session date, the total number of orders, and the total order value for that day.
    DataFrames: sessions, order_summary
    sessions
    session_id:int64 user_id:int64 session_date:datetime64[ns]
    order_summary
    order_id:int64 user_id:int64 order_value:int64 order_date:datetime64[ns]
    Code:
    import pandas as pd
    df1=sessions
    df2=order_summary
    df=pd.merge(df1,df2,left_on=['user_id','session_date'],right_on=['user_id','order_date'])
    df=df.drop(['session_id','order_date'],axis=1)
    df=df.drop_duplicates()
    df=df.groupby(['user_id','session_date']).agg({'order_id':'count','order_value':'sum'}).reset_index()
    df=df.rename(columns={'order_id':'total_orders','order_value':'total_order_value'})
    df
    #pythonprogramming #dataframes #merge #drop #duplicate #groupby #reset #rename #functions #used #question #available #stratascratch #platform #mastering #technology #like #share #subscribemychannel

ความคิดเห็น • 3