I would like to read in an excel spreadsheet to python / pandas, but have the formulae instead of the cell results.
For example, if cell A1 is 25, and cell B1 is =A1, I would like my dataframe to show:
25 =A1
Right now it shows:
25 25
How can I do so?
OpenPyXL
provides this capacity out-of-the-box. See here and here. An example:
from openpyxl import load_workbook
import pandas as pd
wb = load_workbook(filename = 'empty_book.xlsx')
sheet_names = wb.get_sheet_names()
name = sheet_names[0]
sheet_ranges = wb[name]
df = pd.DataFrame(sheet_ranges.values)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With