Problem in applying Vlookup using Openpyxl in Python

Viewed 25

I have four worksheets within the same Workbook. Each of four sheets is shown below:

  1. General Assumption Sheet

enter image description here

  1. Ref Tariff Sheet

enter image description here

  1. Plant Parameter Sheet

enter image description here

  1. Indexed Tariff Sheet (need to populate this with Vlookups and Hlookups)

enter image description here

I have been trying to use both Vlookup and Hlookup in Python to match the plant name and year to get the desired value but I am getting errors.

To populate the Indexed Tariff Sheet, I need to match the Plant name in it with:

  1. the same plant name e.g. Engro_PWR which has a value of 0.0501, in Ref Tariff Sheet. Then,

  2. Multiply that value ( i.e. 0.0501) with the US CPI(in General Assumption Sheet) / US CPI (Plant Parameter Sheet) after matching both the years and plant names.

For example if the year is 2022 and Plant is Engro_PWR , then it becomes 0.0501*(269.73/216.74)

I am using Openpyxl only at the moment.

Any help would be very appreciated.

Code:

current_year=indexed_tariff['C1'].value
column_cell = 3

i='Engro_PWR'
if indexed_tariff['C1'].value <= 2027 and indexed_tariff['C1'].value > 1997:
    vlookup=pd.merge(data_FuelCost,to_dframe[['Fuel Price (Ref Values-Yearly)','Fuel Cost (Reference)']], on='Fuel Price (Ref Values-Yearly)',how='left')
    
    indexed_tariff[column_cell+str(row+5)] = str(i)

data_FuelCost is Ref Tariff Sheet

Error:

KeyError: "['Fuel Cost (Reference)'] not in index"

0 Answers
Related