Skip to content

Instantly share code, notes, and snippets.

@samirsaci
Created April 27, 2021 15:09
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samirsaci/919be1cf5f68b8272565dbb8126de66a to your computer and use it in GitHub Desktop.
Save samirsaci/919be1cf5f68b8272565dbb8126de66a to your computer and use it in GitHub Desktop.
Account perform
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