0

I have a data-frame called 'df_main' in which the # of rows changes with every import of a csv from the user. No matter that amount of rows, the row 'salon totals' and column 'Paid_BB_Percent' will always exist. I would like to copy the data from df_main.loc['salon totals', 'Paid_BB_Percent] and make a new column on the end of the data-frame called 'Store_BB_Percent' where every cell in the column contains a copy of this data.

The idea is that I am going to have another data-frame which will contain a row df_manager = df_main[df_main['Employee'].str.contains(manager_name)] that will be used to find a specific manager row by user input, then a new column will be added like this: df_manager['Manager_BB_Bonus'] = (df_manager['Service_Sales'] - df_manager['Service_Breakpoint']) * (df_manager['Store_BB_Percent']).round(2)

Another, and better way to do this, would be to just multiply df_main.iloc['salon totals', 'Paid_BB_Percent'] by df_manager['Manager_Service_Diff'] like this:

df_manager['Manager_BB_Bonus'] = (df_main.loc['salon totals', 'Paid_BB_Percent'] * df_manager['Manager_Service_Diff'])

The issue with this is when I run:

df_manager = df_main[df_main['Employee'].str.contains(manager_name)] df_manager['Service_Breakpoint'] = 1700 df_manager['Manager_Service_Diff'] = (df_manager['Service_Sales'] - df_manager['Service_Breakpoint']) df_manager['Manager_BB_Bonus'] = (df_main.loc['salon totals', 'Paid_BB_Percent'] * df_manager['Manager_Service_Diff']) df_manager

I get the error: "KeyError: 'the label [salon totals] is not in the [index]'"

Any help is appreciated.

6seven8
  • 97
  • 1
  • 14
  • You are trying to multiply a dataframe to a series. What is expected multiplication operation? – mad_ Aug 01 '18 at 15:42
  • I don't see what you are saying.. This doesn't work either... `df_manager['Manager_BB_Bonus'] = (df_main.loc['salon totals', 'Paid_BB_Percent'] * df_manager.loc['salon totals', 'Manager_Service_Diff'])` – 6seven8 Aug 01 '18 at 15:48
  • What does not work? I have posted an answer. – mad_ Aug 01 '18 at 15:50
  • https://stackoverflow.com/questions/31593201/pandas-iloc-vs-ix-vs-loc-explanation-how-are-they-different – mad_ Aug 01 '18 at 15:53
  • Ok. So I was able to do it by using integer location... `df_manager['Manager_BB_Bonus'] = (df_main.iloc[-1, 5] * df_manager['Manager_Service_Diff'])` for anyone who needs this in the future. – 6seven8 Aug 01 '18 at 16:23

1 Answers1

0

If you are trying to multiply three series. Assuming you are trying to multiply the first value

 df_main['salon totals'][0]* df_main['Paid_BB_Percent'][0]* df_main['Manager_Service_Diff'][0]
mad_
  • 8,121
  • 2
  • 25
  • 40
  • I am trying to multiple a single cell from row 'salon totals' and column 'Paid_BB_Percent' with `df_main['Manager_Service_Diff']` – 6seven8 Aug 01 '18 at 15:51