apteco


Nameapteco JSON
Version 0.8.1 PyPI version JSON
download
home_pagehttps://help.apteco.com/python/index.html
SummaryA Python package for interacting with Apteco Marketing Suite resources via the Apteco API.
upload_time2023-07-18 09:53:50
maintainer
docs_urlNone
authorApteco Ltd
requires_python>=3.6.1,<4.0.0
licenseApache-2.0
keywords apteco faststats orbit api marketing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            **************
  Quickstart
**************

Requirements
============

* Python 3.6+
* Access to an installation of the Apteco API

The Apteco API (which also goes under the name **Orbit API**)
is part of the Apteco Orbit™ installation.
If you have access to Apteco Orbit™, you also have access to the Apteco API!
If you're not sure about this, contact whoever administers your Apteco software,
or get in touch with Apteco support (support@apteco.com).

Installation
============

You can install the package the usual way from PyPI using ``pip``:

.. code-block:: console

   python -m pip install apteco

Logging in
==========

Your login credentials are the same username and password
you would use to log in to Apteco Orbit™:

.. code-block:: python

    >>> from apteco import login
    >>> my_session = login("https://my-site.com/OrbitAPI", "my_data_view", "my_system", "jdoe")

You will be asked to enter your password in the terminal, which won't be echoed.
If Python is unable to ask for your password in this way,
it will provide a pop-up box instead.
This might appear in the background,
so check your taskbar for a new window if nothing seems to be happening.

If you don't want to enter your password every time,
there's also a ``login_with_password`` function which takes your password
as a fifth argument:

.. code-block:: python

    >>> from apteco import login_with_password
    >>> my_session = login_with_password(
    ...     "https://my-site.com/OrbitAPI",
    ...     "my_data_view",
    ...     "my_system",
    ...     "jdoe",
    ...     "password",  # password is in plain sight in the code!
    ... )

Tables
======

Tables are accessed through the ``tables`` attribute on the ``Session`` object.
You can retrieve a table using its name:

.. code-block:: python

    >>> bookings = my_session.tables["Bookings"]

``Table`` objects have properties for various metadata:

.. code-block:: python

    >>> print(
    ...     f"There are {bookings.total_records:,}"
    ...     f" {bookings.plural.lower()}"
    ...     f" in the system."
    ... )
    There are 2,130,081 bookings in the system.

Variables
=========

Variables are accessed through the ``variables`` attribute
on the ``Session`` object.
You can retrieve a variable using its name or description:

.. code-block:: python

    >>> occupation = my_session.variables["peOccu"]  # name
    >>> cost = my_session.variables["Cost"]  # description

Each table also has a ``variables`` attribute
for accessing the variables on that table:

.. code-block:: python

    >>> occupation = people.variables["peOccu"]
    >>> cost = bookings.variables["Cost"]

For convenience you can access variables by indexing into the ``Table`` itself:

.. code-block:: python

    >>> occupation = people["peOccu"]
    >>> cost = bookings["Cost"]

``Variable`` objects have attributes with various metadata:

.. code-block:: python

    >>> occupation.type
    <VariableType.SELECTOR: 'Selector'>
    >>> cost.description
    'Cost'

Creating selections
===================

You can use the Python operators with ``Variable`` objects to build selections
based on criteria and return a count:

.. code-block:: python

    >>> sweden = bookings["Destination"] == "29"
    >>> sweden.count()
    25207

You can specify multiple values using any *iterable*:

.. code-block:: python

    >>> people = my_session.tables["People"]
    >>> high_earners = people["Income"] == (f"{i:02}" for i in range(7, 12))
    >>> high_earners.count()
    7114

You can use other operators as well; for example, to exclude values:

.. code-block:: python

    >>> households = my_session.tables["Households"]
    >>> uk_only = households["Region"] != "14"  # 14 is Channel Islands
    >>> uk_only.count()
    741572

Or to allow a range of values:

.. code-block:: python

    >>> low_profit = bookings["Profit"] <= 25
    >>> low_profit.count()
    211328

.. code-block:: python

    >>> second_half_of_alphabet = people["Surname"] >= "N"
    >>> second_half_of_alphabet.count()
    410954

Date and DateTime variables use the built-in ``datetime`` module:

.. code-block:: python

    >>> from datetime import date, datetime
    >>> bookings_before_2019 = bookings["Booking Date"] <= date(2018, 12, 31)
    >>> bookings_before_2019.count()
    972439

You can take advantage of functionality available in other Python packages:

.. code-block:: python

    >>> from dateutil.relativedelta import relativedelta
    >>> under_30 = people["DOB"] >= date.today() - relativedelta(years=30)
    >>> under_30.count()
    207737

Combining selections
====================

You can use the ``&`` ``|`` operators to combine selection criteria:

.. code-block:: python

    >>> sweden = bookings["Destination"] == "29"
    >>> cost_at_least_2k = bookings["Cost"] >= 2000
    >>> expensive_sweden = sweden & cost_at_least_2k
    >>> expensive_sweden.count()
    632
    >>> student = people["Occupation"] == "4"
    >>> under_21 = people["DOB"] >= date.today() - relativedelta(years=21)
    >>> eligible_for_discount = student | under_21
    >>> eligible_for_discount.count()
    188364

The ``~`` operator negates a selection:

.. code-block:: python

    >>> pay_full_price = ~eligible_for_discount
    >>> pay_full_price.count()
    968189

You can join clauses from different tables and it will automatically handle
the required table changes:

.. code-block:: python

    >>> high_affordability = high_earners | cost_at_least_2k  # will resolve to people
    >>> high_affordability.count()
    56096
    >>> high_affordability.table_name
    'People'

The left-most clause determines the resolve table:

.. code-block:: python

    >>> female = people["Gender"] == "F"
    >>> usa = bookings["Destination"] == "38"
    >>> female.table_name
    'People'
    >>> usa.table_name
    'Bookings'
    >>> (female & usa).table_name
    'People'
    >>> (usa & female).table_name
    'Bookings'

You can manually set the resolve table using the ``*`` operator:

.. code-block:: python

    >>> bookings_by_under_21s = bookings * under_21
    >>> bookings_by_under_21s.count()
    135100
    >>> bookings_by_under_21s.table_name
    'Bookings'

Compound clauses follow Python operator precedence:

.. code-block:: python

    >>> student_or_young_female = student | female & under_21
    >>> student_or_young_female.count()
    166708
    >>> student_or_female_must_be_young = (student | female) & under_21
    >>> student_or_female_must_be_young.count()
    49225

Be especially careful where compound clauses involve table changes:

.. code-block:: python

    >>> women_to_sweden = female & sweden
    >>> women_to_sweden.count()  # selection on People table
    8674
    >>> audience_1 = bookings * (female & sweden)
    >>> audience_1.count()  # bookings by women who've been to sweden
    23553
    >>> audience_2 = (bookings * female) & sweden
    >>> audience_2.count()  # bookings made by a woman, with destination of sweden
    8687

Creating data grids
===================

You can create a data grid from a table:

.. code-block:: python

    >>> urn = bookings["Booking URN"]
    >>> dest = bookings["Destination"]
    >>> occupation = people["Occupation"]
    >>> town = households["Town"]
    >>> datagrid = bookings.datagrid([urn, dest, cost, occupation, town])

Convert it to a Pandas DataFrame:

.. code-block:: python

    >>> datagrid.to_df()
        Booking URN    Destination     Cost       Occupation        Town
    0      10001265         France  1392.35  Sales Executive    Aberdeen
    1      10001266         France   780.34  Sales Executive    Aberdeen
    2      10011532        Germany   181.68    Manual Worker      Alford
    3      10011533        Germany   300.67    Manual Worker      Alford
    4      10015830   Unclassified   228.70  Sales Executive     Macduff
    ..          ...            ...      ...              ...         ...
    995    10996176  United States   241.24     Professional  Glenrothes
    996    10996177         Greece   343.23          Manager  Glenrothes
    997    10996178  United States   636.22          Manager  Glenrothes
    998    10996179  United States   356.21          Manager  Glenrothes
    999    10996180  United States   438.20          Manager  Glenrothes

    [1000 rows x 5 columns]

You can use a base selection to filter the records:

.. code-block:: python

    >>> sweden = dest == "29"
    >>> sweden_datagrid = sweden.datagrid([urn, dest, cost, occupation, town])
    >>> sweden_datagrid.to_df()
        Booking URN Destination     Cost       Occupation           Town
    0      10172319      Sweden  1201.81  Sales Executive         Bolton
    1      10384970      Sweden   344.30          Manager     Chelmsford
    2      10421011      Sweden   322.89  Sales Executive        Croydon
    3      10425298      Sweden   880.02          Student  South Croydon
    4      10479109      Sweden   172.91    Retail Worker       Nantwich
    ..          ...         ...      ...              ...            ...
    995    11471824      Sweden   118.76  Sales Executive    King's Lynn
    996    11576762      Sweden   652.38    Public Sector        Redhill
    997    11576764      Sweden   183.36    Public Sector        Redhill
    998    11682962      Sweden  1166.38          Manager         London
    999    11754655      Sweden   192.45  Sales Executive          Ascot

    [1000 rows x 5 columns]

You can filter using a selection from a different table:

.. code-block:: python

    >>> manchester = households["Region"] == "13"
    >>> manc_datagrid = manchester.datagrid(
    ...     [urn, dest, cost, occupation, town], table=bookings
    ... )
    >>> manc_datagrid.to_df()
        Booking URN    Destination     Cost       Occupation         Town
    0      10172319         Sweden  1201.81  Sales Executive       Bolton
    1      10172320  United States  1616.80  Sales Executive       Bolton
    2      10173729         France   581.71          Student       Bolton
    3      10173730         France  2224.70          Student       Bolton
    4      10177047         France   686.53  Sales Executive       Bolton
    ..          ...            ...      ...              ...          ...
    995    11739340      Australia   316.60     Professional  Stalybridge
    996    11739342   Unclassified   316.58  Sales Executive  Stalybridge
    997    12087034         Greece  1305.66    Public Sector   Altrincham
    998    12087035  United States   585.65    Public Sector   Altrincham
    999    12087036      Australia   496.64    Public Sector   Altrincham

    [1000 rows x 5 columns]

Creating cubes
==============

You can create a cube from a table:

.. code-block:: python

    >>> occupation = people["Occupation"]
    >>> income = people["Income"]
    >>> gender = people["Gender"]
    >>> cube = people.cube([occupation, income, gender])

Convert it to a Pandas DataFrame:

.. code-block:: python

    >>> df = cube.to_df()
    >>> df.head(10)
                                   People
    Occupation    Income  Gender
    Manual Worker <£10k   Female    15624
                          Male       5321
                          Unknown       5
                  £10-20k Female    43051
                          Male       5992
                          Unknown      25
                  £20-30k Female     1498
                          Male        649
                          Unknown      14
                  £30-40k Female      675

You can pivot the dimensions to make it easier to read:

.. code-block:: python

    >>> df.unstack(level=0)
                       People          ...
    Occupation       Director Manager  ... Student Unemployed
    Income   Gender                    ...
    <£10k    Female      1279    4649  ...   28002      21385
             Male         832    2926  ...   14296       8386
             Unknown        4      16  ...      10        155
    £10-20k  Female      4116   16665  ...   39462      17230
             Male        2139    9123  ...   17917       4532
             Unknown        9      47  ...      25        368
    £100k+   Female         2       1  ...       2          0
             Male           1       0  ...       3          0
             Unknown        1       0  ...       1          0
    £20-30k  Female      1267    6238  ...    6669       5747
             Male        1050    5315  ...    5274       1345
             Unknown        5      45  ...      22        236
    £30-40k  Female      1591    6621  ...    5690       3117
             Male        1940    9713  ...    6345       1049
             Unknown       46     140  ...      63        519
    £40-50k  Female       265     965  ...     587        262
             Male         518    1800  ...     943        115
             Unknown       22      58  ...      29        110
    £50-60k  Female       336     806  ...     425        277
             Male         607    1677  ...     692         69
             Unknown       47      88  ...      64         89
    £60-70k  Female        40     112  ...      54         58
             Male          96     220  ...      95          8
             Unknown       11      16  ...      17         17
    £70-80k  Female        44      96  ...      42         27
             Male         102     179  ...      63          5
             Unknown       12      22  ...      15          5
    £80-90k  Female        11      11  ...       3          0
             Male          14      13  ...      16          0
             Unknown        4       3  ...       5          0
    £90-100k Female         1       0  ...       1          1
             Male          11       7  ...       4          0
             Unknown        3       6  ...       9          0

    [33 rows x 10 columns]

You can use a base selection to filter the records:

.. code-block:: python

    >>> occupation = people["Occupation"]
    >>> region = households["Region"]
    >>> student = occupation == "4"
    >>> student_cube = student.cube([occupation, dest, region])
    >>> student_df = student_cube.to_df()
    >>> student_df.head()
                                                                     People
    Occupation    Destination Region
    Manual Worker Australia   North                                       0
                              North West (Excluding Gtr Manchester)       0
                              South East (Outside M25 )                   0
                              South West                                  0
                              East Midlands                               0

Selecting only cells where ``Occupation`` is *Student*,
and pivoting ``Destination`` dimension:

.. code-block:: python

    >>> student_df.loc["Student"].unstack(level=0)
                                             People          ...
    Destination                           Australia Denmark  ... Sweden United States
    Region                                                   ...
    Channel Islands                              46       1  ...     10            81
    East Anglia                                 989       0  ...    109           905
    East Midlands                              1956       0  ...    174          1762
    Greater Manchester                         1197       1  ...    147          1089
    North                                       959       2  ...    115           869
    North West (Excluding Gtr Manchester)      1594       2  ...    177          1429
    Northern Ireland                            467       0  ...     42           492
    Scotland                                   2061       1  ...    224          1964
    South East (Inside M25 )                   3935       0  ...    390          3580
    South East (Outside M25 )                  6255       1  ...    608          5587
    South West                                 2310       0  ...    182          2037
    Wales                                       974       0  ...    122           860
    West Midlands                              2643       0  ...    288          2362
    Yorkshire and Humber                       2295       0  ...    249          2089

    [14 rows x 19 columns]

You can use a selection from a different table to filter the records in the cube:

.. code-block:: python

    >>> manchester = region == "13"
    >>> manc_cube = manchester.cube([occupation, dest, region], table=bookings)
    >>> manc_cube.to_df()
                                                                      Bookings
    Occupation    Destination  Region
    Manual Worker Australia    North                                         0
                               North West (Excluding Gtr Manchester)         0
                               South East (Outside M25 )                     0
                               South West                                    0
                               East Midlands                                 0
                                                                        ...
    Retired       South Africa Scotland                                      0
                               Wales                                         0
                               Northern Ireland                              0
                               Greater Manchester                            0
                               Channel Islands                               0

    [2660 rows x 1 columns]

You can find the complete documentation
including a more thorough `tutorial <https://help.apteco.com/python/tutorial.html>`_
on the `Apteco website <https://help.apteco.com/python/index.html>`_.
            

Raw data

            {
    "_id": null,
    "home_page": "https://help.apteco.com/python/index.html",
    "name": "apteco",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6.1,<4.0.0",
    "maintainer_email": "",
    "keywords": "Apteco,FastStats,Orbit,API,Marketing",
    "author": "Apteco Ltd",
    "author_email": "support@apteco.com",
    "download_url": "https://files.pythonhosted.org/packages/da/60/423ce4c773460f9fcd48b3e4a72fd5d9930a3f29efcadf6b7a97b554154b/apteco-0.8.1.tar.gz",
    "platform": null,
    "description": "**************\n  Quickstart\n**************\n\nRequirements\n============\n\n* Python 3.6+\n* Access to an installation of the Apteco API\n\nThe Apteco API (which also goes under the name **Orbit API**)\nis part of the Apteco Orbit\u2122 installation.\nIf you have access to Apteco Orbit\u2122, you also have access to the Apteco API!\nIf you're not sure about this, contact whoever administers your Apteco software,\nor get in touch with Apteco support (support@apteco.com).\n\nInstallation\n============\n\nYou can install the package the usual way from PyPI using ``pip``:\n\n.. code-block:: console\n\n   python -m pip install apteco\n\nLogging in\n==========\n\nYour login credentials are the same username and password\nyou would use to log in to Apteco Orbit\u2122:\n\n.. code-block:: python\n\n    >>> from apteco import login\n    >>> my_session = login(\"https://my-site.com/OrbitAPI\", \"my_data_view\", \"my_system\", \"jdoe\")\n\nYou will be asked to enter your password in the terminal, which won't be echoed.\nIf Python is unable to ask for your password in this way,\nit will provide a pop-up box instead.\nThis might appear in the background,\nso check your taskbar for a new window if nothing seems to be happening.\n\nIf you don't want to enter your password every time,\nthere's also a ``login_with_password`` function which takes your password\nas a fifth argument:\n\n.. code-block:: python\n\n    >>> from apteco import login_with_password\n    >>> my_session = login_with_password(\n    ...     \"https://my-site.com/OrbitAPI\",\n    ...     \"my_data_view\",\n    ...     \"my_system\",\n    ...     \"jdoe\",\n    ...     \"password\",  # password is in plain sight in the code!\n    ... )\n\nTables\n======\n\nTables are accessed through the ``tables`` attribute on the ``Session`` object.\nYou can retrieve a table using its name:\n\n.. code-block:: python\n\n    >>> bookings = my_session.tables[\"Bookings\"]\n\n``Table`` objects have properties for various metadata:\n\n.. code-block:: python\n\n    >>> print(\n    ...     f\"There are {bookings.total_records:,}\"\n    ...     f\" {bookings.plural.lower()}\"\n    ...     f\" in the system.\"\n    ... )\n    There are 2,130,081 bookings in the system.\n\nVariables\n=========\n\nVariables are accessed through the ``variables`` attribute\non the ``Session`` object.\nYou can retrieve a variable using its name or description:\n\n.. code-block:: python\n\n    >>> occupation = my_session.variables[\"peOccu\"]  # name\n    >>> cost = my_session.variables[\"Cost\"]  # description\n\nEach table also has a ``variables`` attribute\nfor accessing the variables on that table:\n\n.. code-block:: python\n\n    >>> occupation = people.variables[\"peOccu\"]\n    >>> cost = bookings.variables[\"Cost\"]\n\nFor convenience you can access variables by indexing into the ``Table`` itself:\n\n.. code-block:: python\n\n    >>> occupation = people[\"peOccu\"]\n    >>> cost = bookings[\"Cost\"]\n\n``Variable`` objects have attributes with various metadata:\n\n.. code-block:: python\n\n    >>> occupation.type\n    <VariableType.SELECTOR: 'Selector'>\n    >>> cost.description\n    'Cost'\n\nCreating selections\n===================\n\nYou can use the Python operators with ``Variable`` objects to build selections\nbased on criteria and return a count:\n\n.. code-block:: python\n\n    >>> sweden = bookings[\"Destination\"] == \"29\"\n    >>> sweden.count()\n    25207\n\nYou can specify multiple values using any *iterable*:\n\n.. code-block:: python\n\n    >>> people = my_session.tables[\"People\"]\n    >>> high_earners = people[\"Income\"] == (f\"{i:02}\" for i in range(7, 12))\n    >>> high_earners.count()\n    7114\n\nYou can use other operators as well; for example, to exclude values:\n\n.. code-block:: python\n\n    >>> households = my_session.tables[\"Households\"]\n    >>> uk_only = households[\"Region\"] != \"14\"  # 14 is Channel Islands\n    >>> uk_only.count()\n    741572\n\nOr to allow a range of values:\n\n.. code-block:: python\n\n    >>> low_profit = bookings[\"Profit\"] <= 25\n    >>> low_profit.count()\n    211328\n\n.. code-block:: python\n\n    >>> second_half_of_alphabet = people[\"Surname\"] >= \"N\"\n    >>> second_half_of_alphabet.count()\n    410954\n\nDate and DateTime variables use the built-in ``datetime`` module:\n\n.. code-block:: python\n\n    >>> from datetime import date, datetime\n    >>> bookings_before_2019 = bookings[\"Booking Date\"] <= date(2018, 12, 31)\n    >>> bookings_before_2019.count()\n    972439\n\nYou can take advantage of functionality available in other Python packages:\n\n.. code-block:: python\n\n    >>> from dateutil.relativedelta import relativedelta\n    >>> under_30 = people[\"DOB\"] >= date.today() - relativedelta(years=30)\n    >>> under_30.count()\n    207737\n\nCombining selections\n====================\n\nYou can use the ``&`` ``|`` operators to combine selection criteria:\n\n.. code-block:: python\n\n    >>> sweden = bookings[\"Destination\"] == \"29\"\n    >>> cost_at_least_2k = bookings[\"Cost\"] >= 2000\n    >>> expensive_sweden = sweden & cost_at_least_2k\n    >>> expensive_sweden.count()\n    632\n    >>> student = people[\"Occupation\"] == \"4\"\n    >>> under_21 = people[\"DOB\"] >= date.today() - relativedelta(years=21)\n    >>> eligible_for_discount = student | under_21\n    >>> eligible_for_discount.count()\n    188364\n\nThe ``~`` operator negates a selection:\n\n.. code-block:: python\n\n    >>> pay_full_price = ~eligible_for_discount\n    >>> pay_full_price.count()\n    968189\n\nYou can join clauses from different tables and it will automatically handle\nthe required table changes:\n\n.. code-block:: python\n\n    >>> high_affordability = high_earners | cost_at_least_2k  # will resolve to people\n    >>> high_affordability.count()\n    56096\n    >>> high_affordability.table_name\n    'People'\n\nThe left-most clause determines the resolve table:\n\n.. code-block:: python\n\n    >>> female = people[\"Gender\"] == \"F\"\n    >>> usa = bookings[\"Destination\"] == \"38\"\n    >>> female.table_name\n    'People'\n    >>> usa.table_name\n    'Bookings'\n    >>> (female & usa).table_name\n    'People'\n    >>> (usa & female).table_name\n    'Bookings'\n\nYou can manually set the resolve table using the ``*`` operator:\n\n.. code-block:: python\n\n    >>> bookings_by_under_21s = bookings * under_21\n    >>> bookings_by_under_21s.count()\n    135100\n    >>> bookings_by_under_21s.table_name\n    'Bookings'\n\nCompound clauses follow Python operator precedence:\n\n.. code-block:: python\n\n    >>> student_or_young_female = student | female & under_21\n    >>> student_or_young_female.count()\n    166708\n    >>> student_or_female_must_be_young = (student | female) & under_21\n    >>> student_or_female_must_be_young.count()\n    49225\n\nBe especially careful where compound clauses involve table changes:\n\n.. code-block:: python\n\n    >>> women_to_sweden = female & sweden\n    >>> women_to_sweden.count()  # selection on People table\n    8674\n    >>> audience_1 = bookings * (female & sweden)\n    >>> audience_1.count()  # bookings by women who've been to sweden\n    23553\n    >>> audience_2 = (bookings * female) & sweden\n    >>> audience_2.count()  # bookings made by a woman, with destination of sweden\n    8687\n\nCreating data grids\n===================\n\nYou can create a data grid from a table:\n\n.. code-block:: python\n\n    >>> urn = bookings[\"Booking URN\"]\n    >>> dest = bookings[\"Destination\"]\n    >>> occupation = people[\"Occupation\"]\n    >>> town = households[\"Town\"]\n    >>> datagrid = bookings.datagrid([urn, dest, cost, occupation, town])\n\nConvert it to a Pandas DataFrame:\n\n.. code-block:: python\n\n    >>> datagrid.to_df()\n        Booking URN    Destination     Cost       Occupation        Town\n    0      10001265         France  1392.35  Sales Executive    Aberdeen\n    1      10001266         France   780.34  Sales Executive    Aberdeen\n    2      10011532        Germany   181.68    Manual Worker      Alford\n    3      10011533        Germany   300.67    Manual Worker      Alford\n    4      10015830   Unclassified   228.70  Sales Executive     Macduff\n    ..          ...            ...      ...              ...         ...\n    995    10996176  United States   241.24     Professional  Glenrothes\n    996    10996177         Greece   343.23          Manager  Glenrothes\n    997    10996178  United States   636.22          Manager  Glenrothes\n    998    10996179  United States   356.21          Manager  Glenrothes\n    999    10996180  United States   438.20          Manager  Glenrothes\n\n    [1000 rows x 5 columns]\n\nYou can use a base selection to filter the records:\n\n.. code-block:: python\n\n    >>> sweden = dest == \"29\"\n    >>> sweden_datagrid = sweden.datagrid([urn, dest, cost, occupation, town])\n    >>> sweden_datagrid.to_df()\n        Booking URN Destination     Cost       Occupation           Town\n    0      10172319      Sweden  1201.81  Sales Executive         Bolton\n    1      10384970      Sweden   344.30          Manager     Chelmsford\n    2      10421011      Sweden   322.89  Sales Executive        Croydon\n    3      10425298      Sweden   880.02          Student  South Croydon\n    4      10479109      Sweden   172.91    Retail Worker       Nantwich\n    ..          ...         ...      ...              ...            ...\n    995    11471824      Sweden   118.76  Sales Executive    King's Lynn\n    996    11576762      Sweden   652.38    Public Sector        Redhill\n    997    11576764      Sweden   183.36    Public Sector        Redhill\n    998    11682962      Sweden  1166.38          Manager         London\n    999    11754655      Sweden   192.45  Sales Executive          Ascot\n\n    [1000 rows x 5 columns]\n\nYou can filter using a selection from a different table:\n\n.. code-block:: python\n\n    >>> manchester = households[\"Region\"] == \"13\"\n    >>> manc_datagrid = manchester.datagrid(\n    ...     [urn, dest, cost, occupation, town], table=bookings\n    ... )\n    >>> manc_datagrid.to_df()\n        Booking URN    Destination     Cost       Occupation         Town\n    0      10172319         Sweden  1201.81  Sales Executive       Bolton\n    1      10172320  United States  1616.80  Sales Executive       Bolton\n    2      10173729         France   581.71          Student       Bolton\n    3      10173730         France  2224.70          Student       Bolton\n    4      10177047         France   686.53  Sales Executive       Bolton\n    ..          ...            ...      ...              ...          ...\n    995    11739340      Australia   316.60     Professional  Stalybridge\n    996    11739342   Unclassified   316.58  Sales Executive  Stalybridge\n    997    12087034         Greece  1305.66    Public Sector   Altrincham\n    998    12087035  United States   585.65    Public Sector   Altrincham\n    999    12087036      Australia   496.64    Public Sector   Altrincham\n\n    [1000 rows x 5 columns]\n\nCreating cubes\n==============\n\nYou can create a cube from a table:\n\n.. code-block:: python\n\n    >>> occupation = people[\"Occupation\"]\n    >>> income = people[\"Income\"]\n    >>> gender = people[\"Gender\"]\n    >>> cube = people.cube([occupation, income, gender])\n\nConvert it to a Pandas DataFrame:\n\n.. code-block:: python\n\n    >>> df = cube.to_df()\n    >>> df.head(10)\n                                   People\n    Occupation    Income  Gender\n    Manual Worker <\u00a310k   Female    15624\n                          Male       5321\n                          Unknown       5\n                  \u00a310-20k Female    43051\n                          Male       5992\n                          Unknown      25\n                  \u00a320-30k Female     1498\n                          Male        649\n                          Unknown      14\n                  \u00a330-40k Female      675\n\nYou can pivot the dimensions to make it easier to read:\n\n.. code-block:: python\n\n    >>> df.unstack(level=0)\n                       People          ...\n    Occupation       Director Manager  ... Student Unemployed\n    Income   Gender                    ...\n    <\u00a310k    Female      1279    4649  ...   28002      21385\n             Male         832    2926  ...   14296       8386\n             Unknown        4      16  ...      10        155\n    \u00a310-20k  Female      4116   16665  ...   39462      17230\n             Male        2139    9123  ...   17917       4532\n             Unknown        9      47  ...      25        368\n    \u00a3100k+   Female         2       1  ...       2          0\n             Male           1       0  ...       3          0\n             Unknown        1       0  ...       1          0\n    \u00a320-30k  Female      1267    6238  ...    6669       5747\n             Male        1050    5315  ...    5274       1345\n             Unknown        5      45  ...      22        236\n    \u00a330-40k  Female      1591    6621  ...    5690       3117\n             Male        1940    9713  ...    6345       1049\n             Unknown       46     140  ...      63        519\n    \u00a340-50k  Female       265     965  ...     587        262\n             Male         518    1800  ...     943        115\n             Unknown       22      58  ...      29        110\n    \u00a350-60k  Female       336     806  ...     425        277\n             Male         607    1677  ...     692         69\n             Unknown       47      88  ...      64         89\n    \u00a360-70k  Female        40     112  ...      54         58\n             Male          96     220  ...      95          8\n             Unknown       11      16  ...      17         17\n    \u00a370-80k  Female        44      96  ...      42         27\n             Male         102     179  ...      63          5\n             Unknown       12      22  ...      15          5\n    \u00a380-90k  Female        11      11  ...       3          0\n             Male          14      13  ...      16          0\n             Unknown        4       3  ...       5          0\n    \u00a390-100k Female         1       0  ...       1          1\n             Male          11       7  ...       4          0\n             Unknown        3       6  ...       9          0\n\n    [33 rows x 10 columns]\n\nYou can use a base selection to filter the records:\n\n.. code-block:: python\n\n    >>> occupation = people[\"Occupation\"]\n    >>> region = households[\"Region\"]\n    >>> student = occupation == \"4\"\n    >>> student_cube = student.cube([occupation, dest, region])\n    >>> student_df = student_cube.to_df()\n    >>> student_df.head()\n                                                                     People\n    Occupation    Destination Region\n    Manual Worker Australia   North                                       0\n                              North West (Excluding Gtr Manchester)       0\n                              South East (Outside M25 )                   0\n                              South West                                  0\n                              East Midlands                               0\n\nSelecting only cells where ``Occupation`` is *Student*,\nand pivoting ``Destination`` dimension:\n\n.. code-block:: python\n\n    >>> student_df.loc[\"Student\"].unstack(level=0)\n                                             People          ...\n    Destination                           Australia Denmark  ... Sweden United States\n    Region                                                   ...\n    Channel Islands                              46       1  ...     10            81\n    East Anglia                                 989       0  ...    109           905\n    East Midlands                              1956       0  ...    174          1762\n    Greater Manchester                         1197       1  ...    147          1089\n    North                                       959       2  ...    115           869\n    North West (Excluding Gtr Manchester)      1594       2  ...    177          1429\n    Northern Ireland                            467       0  ...     42           492\n    Scotland                                   2061       1  ...    224          1964\n    South East (Inside M25 )                   3935       0  ...    390          3580\n    South East (Outside M25 )                  6255       1  ...    608          5587\n    South West                                 2310       0  ...    182          2037\n    Wales                                       974       0  ...    122           860\n    West Midlands                              2643       0  ...    288          2362\n    Yorkshire and Humber                       2295       0  ...    249          2089\n\n    [14 rows x 19 columns]\n\nYou can use a selection from a different table to filter the records in the cube:\n\n.. code-block:: python\n\n    >>> manchester = region == \"13\"\n    >>> manc_cube = manchester.cube([occupation, dest, region], table=bookings)\n    >>> manc_cube.to_df()\n                                                                      Bookings\n    Occupation    Destination  Region\n    Manual Worker Australia    North                                         0\n                               North West (Excluding Gtr Manchester)         0\n                               South East (Outside M25 )                     0\n                               South West                                    0\n                               East Midlands                                 0\n                                                                        ...\n    Retired       South Africa Scotland                                      0\n                               Wales                                         0\n                               Northern Ireland                              0\n                               Greater Manchester                            0\n                               Channel Islands                               0\n\n    [2660 rows x 1 columns]\n\nYou can find the complete documentation\nincluding a more thorough `tutorial <https://help.apteco.com/python/tutorial.html>`_\non the `Apteco website <https://help.apteco.com/python/index.html>`_.",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "A Python package for interacting with Apteco Marketing Suite resources via the Apteco API.",
    "version": "0.8.1",
    "project_urls": {
        "Homepage": "https://help.apteco.com/python/index.html",
        "Repository": "https://github.com/Apteco/py-apteco"
    },
    "split_keywords": [
        "apteco",
        "faststats",
        "orbit",
        "api",
        "marketing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c55fff55a6b20ade71eca178798efcfad6881df57716a9ed5d5f0636e9e3d036",
                "md5": "ee3a7fc3fbe0304864432fa0157187d7",
                "sha256": "396f1e1c77afc5b8b6329d2fc1aa2ba6bad9261192a7ec8a6858023c6b40f525"
            },
            "downloads": -1,
            "filename": "apteco-0.8.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ee3a7fc3fbe0304864432fa0157187d7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6.1,<4.0.0",
            "size": 43234,
            "upload_time": "2023-07-18T09:53:48",
            "upload_time_iso_8601": "2023-07-18T09:53:48.039883Z",
            "url": "https://files.pythonhosted.org/packages/c5/5f/ff55a6b20ade71eca178798efcfad6881df57716a9ed5d5f0636e9e3d036/apteco-0.8.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "da60423ce4c773460f9fcd48b3e4a72fd5d9930a3f29efcadf6b7a97b554154b",
                "md5": "99fe6d4500ccd1b2d7713359cbe91240",
                "sha256": "8b2ed6e84560126955831051e5e6eb0368e532d60cfff511a687f6235cb76734"
            },
            "downloads": -1,
            "filename": "apteco-0.8.1.tar.gz",
            "has_sig": false,
            "md5_digest": "99fe6d4500ccd1b2d7713359cbe91240",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6.1,<4.0.0",
            "size": 45680,
            "upload_time": "2023-07-18T09:53:50",
            "upload_time_iso_8601": "2023-07-18T09:53:50.157032Z",
            "url": "https://files.pythonhosted.org/packages/da/60/423ce4c773460f9fcd48b3e4a72fd5d9930a3f29efcadf6b7a97b554154b/apteco-0.8.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-18 09:53:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Apteco",
    "github_project": "py-apteco",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "apteco"
}
        
Elapsed time: 0.23446s