Skip to main content

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!

Image of C3 Chart

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 created by Prof Daniel McCarthy.

Below are some of the methods found within this library. Not all methods are in the readme, so open-up the lifestream.py file for some Easter eggs.

Transaction Log Creation

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.

Monthly Sales Chart

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.

Monthly Sales Chart

Cohort Retention 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.

Cohort Retention Chart

Monthly Acquisition Chart

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.

Monthly New Users Chart

The C3 Chart 🤩

lifestream.c3chart(transaction_log, customer_id, datetime_col, ordervalue_col, title="Total Quarterly Sales by Acquisition Cohort Over Time")
  • transaction_log is a dataframe of your transactional data.
  • customerid_col represents the column of the dataframe which contains the unique user id associated with the transaction.
  • datetime_col represents the column of the dataframe which contains the datetime of the transaction.
  • ordervalue_col represents the column of the dataframe which contains the monetary value of the transaction.
  • title optional represents the title of the chart.

Image of C3 Chart

Contributing

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

License

MIT

Metadata

Release files for lifestream 0.0.18

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lifestream 0.0.18
File Size Uploaded
lifestream-0.0.18.tar.gz 9.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lifestream 0.0.18
File Interpreter ABI Platform
lifestream-0.0.18-py3-none-any.whl Python 3 none any Details

Total release size: 18.3 kB

Release files / lifestream-0.0.18.tar.gz

Download URL lifestream-0.0.18.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
938b1cd97e216746bb913fd2bb2196502a479d3159ede5f25375338f5dee1cff
BLAKE2b-256 checksum
How to use checksums
7001a54059057dd1c9541631cd7cec50c43e70db7e36d14908b0b8063c938173
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / lifestream-0.0.18-py3-none-any.whl

Download URL lifestream-0.0.18-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
65adb8fa41a6107cbd1b2cd857b5a2d682a37fe71a1ad20a2a739849ea0f6156
BLAKE2b-256 checksum
How to use checksums
93cb0cd2dd70cae410c9e428c04af25fd800b1a8084a114d7d561e5948543a10
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.0.18 This release

2 release files

0.0.17

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page