Preprocessing the data using Pivot table