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[7], 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.
Jon
Hi Jon,
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.
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.
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.
Try this
internet_sales = xl(
Hi, @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.