1

I am trying to create an excel file where users can manipulate the values in the columns to change the value of an output depending on their needs. I run these calculations the first time using pandas and then export to an excel file using:

df.to_excel(writer, 'ExportSheet')

I am trying to make the output column a formula that depends on the other columns in the dataframe For example:

I have 4 columns:

UniqueColumnName1 | Coeff1 | UniqueColumnName2 | Coeff2

 125              | 2      | -24               | 2

In pandas I create a column:

df['Output'] = df['UniqueColumnName1'] * df['Coeff1'] - df['UniqueColumnName2'] * df['Coeff2']

I want the output column to be an excel formula referencing the values in each of those columns so users can change the value of 125 to say 250. Is there a way to do this in pandas?

zeetitan
  • 35
  • 5
  • Why wouldn't you just define this formula explicitly in Excel, rather than go through the trouble of creating a formula in Pandas only to be evaluated in Excel? It's unnecessary overhead IMO. – rahlf23 Nov 02 '18 at 15:07
  • All of these columns and values are generated programmatically, so when I start I have no excel file to refer to. I end up creating these column names and values which I then export to excel. Also the number of columns etc. changes so I am trying to find a general way to export formulas – zeetitan Nov 02 '18 at 15:18
  • I would refer you here for some insight: https://stackoverflow.com/q/18024742/8146556 – rahlf23 Nov 02 '18 at 15:22

0 Answers0