Search code examples
pythonrpy2

Running embedded R gives a NameError


I'm a python newbie trying to follow along with this great blog on finding seasonal customers:

Python Code for Identifying Seasonal Customers

However, I am stuck on one of the last steps. The code is this:

customerTS = stats.ts(dataForOwner.SENDS.astype(int),
        start=base.c(startYear,startMonth),
        end=base.c(endYear, endMonth),
        frequency=12)

I get this error: NameError: name 'dataForOwner' is not defined

Edit I should add that this last line is also in the code block but I still get error without including:

customerTS = stats.ts(dataForOwner.SENDS.astype(int),
        start=base.c(startYear,startMonth),
        end=base.c(endYear, endMonth),
        frequency=12)
r.assign('customerTS', customerTS)

I have googled quite a bit and having no luck getting it to work.


Solution

  • NameError: name 'dataForOwner' is not defined
    

    Is raised by Python itself to indicate it is unable to find an object called dataForOWner in the current context. To experience it yourself, just start a new Python terminal and type x (a variable name that does not exist).

    The issue is either with the blog your refer to (the definition of dataForOwner is missing) or with that definition forgotten by a user trying to reproduce that blog.