Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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