0

I would like to know why the code below works fine when executed from Python interpreter but it returns no value when I "pack" it into the file.

import os
import pandas as pd
getFile = (input('\nEnter Excel file name: ')).lower()
getTab = (input('\nEnter tab name: ')).lower()
fileName = os.path.join(os.getcwd() + '\\' + getFile)
pd.read_excel(fileName, sheet_name=getTab, header=None)

Is there any reason I can't run this code from someFile.py? What I do wrong? Many thanks for your kind help. Please, be forgiving, I'm not a professional or skilful coder.

1 Answer 1

1

You have to give a name to the dataframe into which the data should be read. Try the code below

df= pd.read_excel(fileName, sheet_name=getTab, header=None)

If you are working in Jupyter notebook, the below line will print the dataframe

df
Sign up to request clarification or add additional context in comments.

2 Comments

many thanks for your kind advice, however, it worked with some modification (i don't use Jupyter). df = pd.read_excel(fileName, sheet_name=getTab, header=None) print(df) Anyway, thanks for giving me a useful hint, I really appreciate your help!
I found a few links with the explanation: link link @mohanys, again many thanks for solving my issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.