I am starting to look into Python in Excel and am currently working through the series on Anaconda by Dave Langer (Basiscs to Combining Tables). I have downloaded the Excel files provided.
Now I am noticing the following:
If I open the first file (Basics), start Python, I can initiate the DataFrame, but then the classical way also ends. If I enter the following: internet_sales, the desired series is generated, but if I use the name of the column, I get the “Python” error message with the diagnostic information: NameError: name ‘SalesAmount’ is not defined. I get this error message with all commands where I use the column names. If I use the column number, everything works.
In the second file (working with columns), which contains the same table and data, I can use the column names and there is no error message.
My question: What am I doing WRONG? Why can’t I use the column names in the first file?
I assume that all files provided by anaconda / Dave Langer are the same and have only been supplemented / modified by the commands of the respective lesson.
Thank you in advance for an understandable explanation or also ideas.
Let’s see if I can help…
Where is the table in relation to the code. It needs to either be to the right or below, or in a sheet to the right as python is processed left to right and top to bottom.
Second, if that’s not the problem, can you share the code you’re trying to use and I’ll see if I can help you debug.
@thewitt thank you very much for your reaction.
I am aware of your first suggestion regarding the alignment of the code and it has been taken into account.
This is the link to the original file provided by Anaconda.
I will try to explain my problem with the attached screenshot. The difference between the code marked in red and the code marked in orange is, as you can see, in the code marked in red I name the column as it is named in the table and in the dataframe, in the code marked in orange I specify the column number instead.
This is the link to the 2nd example file from Anaconda. The problem I described above does not exist here.
I have no idea why the “problem” exists in my case. Is it because I work on a European system? I am grateful for any ideas / help.
Sorry for the slow response. I’ve been traveling and the internet here is… substandard.
It looks like you need to add the key word argument headers=True where you’re defining internet_sales.
internet_sales = xl(
, headers=True) and that should iron this out.
@thewitt thank you for the hint with the “header”. I had already used this when naming the dataframe.
The exciting thing for me, however, is that I used “header” and not “headers”.
Now it works as usual. What is new for me is that “header” also works, but the column numbers have to be specified.