Skip to main content

The fastest way to make sense of a transaction log.

Project description

Lifestream

Lifestream is a Python library to make sense out of your transaction logs. Import a log of your transactional data and let's explore!

Installation

Use the package manager pip to install lifestream.

pip install lifestream

Transactional Data

At a minimum, the transactional data you import should have the following:

  • OrderID assoiated with transaction
  • Unique user id associated with transaction
  • Date of transaction
  • Monetary value of transaction
order_id user_id date monetary_value
768 13 09/13/2020 $15.12
769 13249 09/13/2020 $240.00
770 11424 09/13/2020 $194.34

Is your transactional data in another kind of format? See the create_transaction_log function below.

Usage

This library is inspired by (many of the charts found in this PowerPoint file)[https://www.dropbox.com/s/x7b7e1kq7gk9id1/summarizing%20buyer%20behavior%20in%20excel%20clean.pptx?dl=0] created by (Prof Daniel McCarthy)[https://twitter.com/d_mccar/status/1299972436117643264].

Below are some of the methods found within this library.

Need to create a transaction log that meets the library's requirements? If your data is as raw as the individually purchased items, try this method.

lifestream.create_transaction_log(df, orderid_col, datetime_col customerid_col, quantity_col, 
unitprice_col)
  • df is a dataframe of your data.
  • orderid_col the column in df DataFrame that denotes the unique order_id.
  • datetime_col the column in df DataFrame that denotes the datetime the purchase was made.
  • customerid_col the column in df DataFrame that denotes the unique customer_id.
  • quantity_col the column in df DataFrame that denotes the quantity of items purchased in an order.
  • unitprice_col the column in df DataFrame that denotes the unit price of items purchased in an order.

Want to plot sales by month?

import lifestream

lifestream.sales_chart(transaction_log, datetime_col, ordervalue_col, customerid_col, customer_count = True, title = 'Sales and Customers Per Month', ylabel1 = 'Number of Customers Per Month', ylabel2 = 'Sales ($) per Month')
  • transaction_log is a dataframe of your transactional data.
  • datetime_col represents the column of the transaction_log dataframe which contains the datetime of the transaction.
  • orderid_col represents the column of the transaction_log dataframe which contains the monetary value of the transaction.
  • customerid_col represents the column of the transaction_log dataframe which contains the unique user id associated with the transaction.
  • customer_count optional boolean to indicate whether overlay of new customers per month is desired
  • title optional represents the title of the chart.
  • ylabel1 optional represents the label on the y-axis of the line chart.
  • ylabel2 optional represents the label on the y-axis of the bar chart.

Want to dig into basic cohort analyses? Plot how many users from a cohort are still spending in subsequent months.

lifestream.cohort_retention_chart(transaction_log, datetime_col, customerid_col, ordervalue_col, cohort1, cohort2, cohort3, title, ylabel)
  • transaction_log is a dataframe of your transactional data.
  • datetime_col represents the column of the dataframe which contains the datetime of the transaction.
  • customerid_col represents the column of the dataframe which contains the unique user id associated with the transaction.
  • ordervalue_col represents the column of the dataframe which contains the monetary value of the transaction.
  • cohort1, cohort2, cohort3 are the three cohorts you are interested in, expressed as 'YYYY-MM' string.
  • title optional is the title for the plot.
  • ylabel optional is the label for the y-axis of the plot.

Plot how many new users you are acquiring per month.

lifestream.new_customers_chart(transaction_log, datetime_col, customerid_col, title, xlabel, ylabel, kind)
  • transaction_log is a dataframe of your transactional data.
  • datetime_col represents the column of the dataframe which contains the datetime of the transaction.
  • customerid_col represents the column of the dataframe which contains the unique user id associated with the transaction.
  • title optional represents the title of the chart.
  • xlabel optional represents the x-axis of the chart.
  • ylabel optional represents the y-axis of the chart.
  • kind optional represents the kind of chart. see the pandas library documentation for the plot method to understand what is available.

Plot the monthly revenue mix by new vs. returning customers.

lifestream.customer_type_revenue_mix(transaction_log, datetime_col, customerid_col, ordervalue_col, figsize = (12,8), rotation = 'vertical'
)
  • transaction_log is a dataframe of your transactional data.
  • datetime_col represents the column of the dataframe which contains the datetime of the transaction.
  • customerid_col represents the column of the dataframe which contains the unique user id associated with the transaction.
  • ordervalue_col represents the column of the dataframe which contains the monetary value of the transaction.
  • figsize optional represents the size of the chart.
  • rotation optional represents the rotation of the x-axis tick marks on the chart.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lifestream-0.0.13.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lifestream-0.0.13-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file lifestream-0.0.13.tar.gz.

File metadata

  • Download URL: lifestream-0.0.13.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0.post20200309 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for lifestream-0.0.13.tar.gz
Algorithm Hash digest
SHA256 0ddacf05a4d895c54f198b8ebd18d183f6c8ad53082e7de8ad4014f7773b0317
MD5 c2eb4eac8a0eed4f95e7efea6c9782ae
BLAKE2b-256 c36eb153e612836fc71761f671c56c30bb396d882f253a1de686336e58e1e6cb

See more details on using hashes here.

File details

Details for the file lifestream-0.0.13-py3-none-any.whl.

File metadata

  • Download URL: lifestream-0.0.13-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0.post20200309 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for lifestream-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 2c94046c98e9bfdb1fabd00520c3c17596cb185f22f11a1c6f7646d606ea20e0
MD5 51e1d1530a90ca722e0895a5cec73af8
BLAKE2b-256 6bdfd361c27cd23a7924b6f75918ed826ff3b2a546730a68d0bf3bc12797d86c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page