Vlookup calculator in Python

Vlookup calculator in Python

Now don't get me wrong, I love Excel as much as the next gal, but I've always found the lack of a good solution for calculating the column index to be a nuisance. I've had a base 26 conversion cheat-sheet bookmarked on my browser for years, but the functionality it lacks is the ability to start your table from somewhere other than column A. Happily, I had a eureka moment while studying the basics of Python. 

I created three dictionaries: COL, PF, and FC.

COL represents letter values from 1-26 and indicates our column's location in the repeating pattern of A-Z.

PF (abbreviation for prefix) represents the first letter of a two letter column label. A consideration here is that PF['a'] is assigned a value of 26 rather than 27. We might assume that PF['a'] would be assigned 27 since in Excel column AA has a position number of 27. However, we have already given COL['a'] a value of 1, therefore we need to give PF['a'] a 0. It represents the number of columns that occur before AA. 

FC (first column) give us an additional number for our function when we want to begin our table on a column other than A. Here we have FC['a']=0 as we don't have to make an adjustment when our table starts on A. 

I have defined two variables for our function, value and FCvalue. For value we enter the column label we are looking up and for FCvalue we enter the column our table will start on. If the input for value only has one letter in it we simply take our column number and subtract the first column, if we're using it. When our input for value had more than one letter we use an index to call only the piece of the input value we want for PF and COL. We then subtract FCvalue as before. 

Voila!

Calculating Inventory on Hand in SQL

Calculating Inventory on Hand in SQL

Pentaho Spoon ETL

Pentaho Spoon ETL