# Imports import pandas as pd # Read the data pos_data = pd.read_csv('Cleaned POS.csv') macroeconomic_data = pd.read_csv('Cleaned Macroeconomic.csv') segment_data = pd.read_csv('Cleaned Segment.csv') mapping_data = pd.read_csv('Cleaned Mapping.csv') trade_data = pd.read_csv('Cleaned Trade.csv') switch_data = pd.read_csv('Cleaned Switch.csv') walk_data = pd.read_csv('Cleaned Walk.csv') # Joins pos_macroeconomic = pos_data.merge(macroeconomic_data, left_on='month_year', right_on='month_year', how='left') pos_macroeconomic_segment = pd.merge(pos_macroeconomic, segment_data, on='Unique_ID', how='left') pos_macro_segment_iri = pos_macroeconomic_segment.merge(mapping_data, left_on='prodDesc', right_on='prod_desc', how='left') pos_macro_segment_iri_trade = pos_macro_segment_iri.merge(trade_data, left_on=['trade_product','period','dateEnding_year'], right_on = ['SKU Descr.','Period','Year'], how='left') pos_macro_segment_iri_trade_walk = pos_macro_segment_iri_trade.merge(walk_data[['SKU', 'WalkAway','cluster']], how='left', left_on='prodDesc', right_on='SKU') pos_macro_segment_iri_trade_walk_switch = pos_macro_segment_iri_trade_walk.merge(switch_data[['SKU','KSwitchIndex', 'CompSwitchIndex']], how='left', left_on='prodDesc', right_on='SKU') pos_macro_segment_iri_trade_walk_switch.to_csv('PosMacroSegmentTradeWalkSwitch.csv')