Pandas Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nimport pandas as pd\n\ndef average_selling_price(prices: pd.DataFrame, units_sold: pd.DataFrame) -> pd.DataFrame:\n    merged_df = pd.merge(prices, units_sold, how=\'left\', on=\'product_id\')\n    merged_df = merged_df[(merged_df[\'purchase_date\'].isna()) | ((merged_df[\'purchase_date\'] >= merged_df[\'start_date\']) & (merged_df[\'purchase_date\'] <= merged_df[\'end_date\']))]\n    # Fill NaN values in units column with 0\n    merged_df[\'units\'].fillna(0, inplace=True)\n    print(merged_df)\n\n    result_df = merged_df.groupby(by=\'product_id\').apply(lambda x: round((x[\'price\']*x[\'units\']).sum() / x[\'units\'].sum(), 2) if x[\'units\'].sum() != 0 else 0).reset_index(name=\'average_price\')\n\n    return result_df\n    \n```
['Pandas']