Home > Enterprise >  Returning a Value from excel using Pandas fails without error message. Returns this instead: <fun
Returning a Value from excel using Pandas fails without error message. Returns this instead: <fun

Time:05-18

I am currently trying to build my own excel reader and tried to imitate/reproduce the results from this simple excersice : https://techoverflow.net/2021/08/01/how-to-read-single-value-from-xlsx-using-pandas/

My program is supposed to return a string from the the excelfile "Test.xlsx", column "C", row 3. It's supposed to return Test Value #123 The Excel file is completely empty, it only contains this one cell with something in it.

Here is what I get instead when I print the value:

<function read_value_from_excel at 0x000001B8C569AF70>

What do I have to do to return the wanted value?

import pandas as pd

filename = "Test.xlsx"


def read_value_from_excel(filename, column="C", row=3):
    """Read a single cell value from an Excel file"""
    return pd.read_excel(filename, skiprows=row - 1, usecols=column, nrows=1, header=None, names=["Value"]).iloc[0]["Value"]

print(read_value_from_excel)

CodePudding user response:

You need to send specified parameters when calling the function. Use:

print(read_value_from_excel(real_filename, your_column, your_row))
  • Related