Created
April 27, 2021 15:09
-
-
Save samirsaci/919be1cf5f68b8272565dbb8126de66a to your computer and use it in GitHub Desktop.
Account perform
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
def process_month(df_clean, month): | |
# Type | |
df_clean['Type'] = df_clean[['Renting', 'Investment']].apply( | |
lambda t: 'Rent.' if t['Renting']=='X' else 'Invest.' if t['Investment']=='X' else 'Purch.', axis = 1) | |
# Quantity | |
dict_qty = dict(zip(['Rent.', 'Purch.', 'Invest.'], ['Rental Units', 'Purchasing Units', 'Invests. Units'])) | |
df_clean['Qty'] = df_clean.apply(lambda t: t[dict_qty[t['Type']]], axis = 1) | |
# Unit Cost | |
dict_cost = dict(zip(['Rent.', 'Purch.', 'Invest.'], ['Unit Rental Cost per month', 'Purchasing Unit Cost', 'Invests. Unit Cost'])) | |
df_clean['Unit Cost'] = df_clean.apply(lambda t: t[dict_cost[t['Type']]], axis = 1) | |
# Report dataframe | |
df_report = df_clean[df_clean.columns[-3:]].copy() | |
df_report.columns = [Month + '-' + str(i) for i in df_report.columns] | |
# Add Month | |
df_month = pd.DataFrame([pd.Series(['', 'May', ''])]) | |
df_month.columns = df_report.columns | |
# Concat | |
df_report = pd.concat([df_month, df_report], ignore_index=False) | |
# Reset index | |
df_report.reset_index(inplace= True) | |
return df_report |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment