I have simple task but it seems to be evading me on how to work it out, I have searched and found the groupby function but it did not work for me hence the post. In short - I have two columns 'Code' & 'Adjusted Cost' in a CSV file. I would like to sum all costs associated with the unique Code (codes identified from numbers 1.1 - 5.15). I am trying df.loc but still no luck.
df['Multiplier'] = df['Code'].map(multipliers)
df['Adjusted Qty'] = df['Quantity'] * df['Multiplier']
df['Adjusted Cost'] = df['Adjusted Qty'] * df['Rate']
df['Total'] = df['Quantity'] * df['Rate']
df['Sqm Cost'] = df['Adjusted Cost'] / gifa
df['Sqm Total Cost'] = df['Sqm Cost'].sum()
total = df['Adjusted Cost'].sum() #totals the entire 'Adjusted Cost Column'
nrm = df.loc[:1.1, 'Adjusted Cost'].sum()
Edit:
Please see attached CSV snippet CSV File
I would like to total the 'Adjusted Cost' column by 'Code' and store it in a variable called 'nrm'. For example in the attached example, 1.1 would total '2500' and 2.4 would total '1100'.
Further edit:
I try the groupby function by using: nrm = df.groupby(['Code']).sum(df['Adjusted Cost'])
Sorry for not been clear I'm very new to pandas and python. The main issue I have with groupby is telling it which Code to look for and which Column to total.