/transport_plan.py Secret
Created
September 9, 2020 04:24
Function 1 to build Transport Routes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create Transport Plan | |
def transport_plan(data, dict_trucks, capacity_dict): | |
# List of Stores per Truck for each DAY | |
df_plan = pd.DataFrame(data.groupby(['Date', 'TruckID'])['Code'].apply(list)) | |
df_plan.columns = ['List_Code'] | |
# List of Box Quantity | |
df_plan['List_BOX'] = data.groupby(['Date', 'TruckID'])['BOX'].apply(list) | |
# Mean of FTL | |
df_plan['FTL'] = data.groupby(['Date', 'TruckID'])['FTL'].mean() | |
df_plan['Capacity(T)'] = df_plan['FTL'].map(capacity_dict) | |
df_plan['List_Loading'] = data.groupby(['Date', 'TruckID'])['Loading(T)'].apply(list) | |
df_plan['Count'] = df_plan['List_Loading'].apply(lambda t: len(t)) | |
df_plan['Total_tons(T)'] = data.groupby(['Date', 'TruckID'])['Loading(T)'].sum() | |
# Distribute: one shipment per col | |
# Stores | |
d = df_plan['List_Code'].apply(pd.Series) | |
for col in d: | |
df_plan["Store%d" % (col+1)] = d[col] | |
# Boxes number | |
d = df_plan['List_BOX'].apply(pd.Series) | |
for col in d: | |
df_plan["Box%d" % (col+1)] = d[col] | |
# Shipments Tonnage | |
d = df_plan['List_Loading'].apply(pd.Series) | |
for col in d: | |
df_plan["Tons%d" % (col+1)] = d[col] | |
# Fill NaN + Drop useless columns | |
df_plan.fillna(0, inplace = True) | |
if 1 == 0: | |
df_plan.drop(['List_Code'], axis = 1, inplace = True) | |
df_plan.drop(['List_BOX'], axis = 1, inplace = True) | |
df_plan.drop(['List_Loading'], axis = 1, inplace = True) | |
return df_plan |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment