I am trying to import data from Excel into Python via Pandas on Mac. When I apply the following code:
import pandas as pd df = pd.read_excel('/Users/andreasmelsen/Desktop/Data.xlsx', sheetname='Sheet1') print(df)
I receive the following error message:
NameError: name 'df' is not defined
Am I missing something? I have no issues importing Pandas.
Edit: I am using Visual Studio Code v1.52.1 with Python 3.9.0 64 bit)
Try:
df = pd.read_excel(r'/Users/andreasmelsen/Desktop/Data.xlsx', sheet_name='Sheet1')
I have added r before the path & corrected the variable name of sheet_name
2.1m questions
2.1m answers
60 comments
57.0k users