plydata.utils.Q

plydata.utils.Q(name)[source]

Quote a variable name

A way to 'quote' variable names, especially ones that do not otherwise meet Python's variable name rules.

Parameters
namestr

Name of variable

Returns
valueobject

Value of variable

Examples

>>> import pandas as pd
>>> from plydata import define
>>> df = pd.DataFrame({'class': [10, 20, 30]})

Since class is a reserved python keyword it cannot be a variable name, and therefore cannot be used in an expression without quoting it.

>>> df >> define(y='class+1')
  File "<string>", line 1
    class+1
        ^
SyntaxError: invalid syntax
>>> df >> define(y='Q("class")+1')
   class   y
0     10  11
1     20  21
2     30  31

Note that it is 'Q("some name")' and not 'Q(some name)'. As in the above example, you do not need to import Q before you can use it.