Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I see the formulas of an excel spreadsheet in pandas / python?

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?

like image 926
ThrowAway23948238 Avatar asked Feb 08 '17 00:02

ThrowAway23948238


1 Answers

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)
like image 133
Aleksey Bilogur Avatar answered Sep 17 '22 15:09

Aleksey Bilogur