<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 <span style="color
Step1:  <span style="color
Step2:  <span style="color
Step3:  <span style="color
Step4:  <span style="color
Step5:  <span style="color
<ASSISTANT_TASK:>
Python Code:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
pd.set_option('max_columns', 50)
mpl.rcParams['lines.linewidth'] = 2
%matplotlib inline
Explanation: <span style="color:black; font-family:Helvetica; font-size:2.5em;">Practical Code to Calculating Customer Lifetime Value (CLV)</span>
<span style="color:gray; font-family:Helvetica; font-size:1em;"><b>Customer Lifetime Value (CLV)</b> is an estimation of the entire net profit attributed to a single customer. It’s an important metric to understand because it helps businesses determine how much is too much to spend on advertising to acquire a single customer.</span>
End of explanation
data = pd.read_csv('/Users/crucker/Desktop/clv_transactions.csv')
data.head(6)
data.tail(6)
Transactions = data['CustomerID'].count()
Customers = data['CustomerID'].max()
MinTransactionDate = data['TransactionDate'].min()
MaxTransactionDate = data['TransactionDate'].max()
Amount = data['Amount'].sum()
summary = [Transactions, Customers, MinTransactionDate, MaxTransactionDate, round(Amount, 2)]
summary
Explanation: <span style="color:black; font-family:Helvetica; font-size:2.5em;">Data Exploration</span>
<span style="color:gray; font-family:Helvetica; font-size:1em;">For this example we’ll calculate CLV from a dataset of roughly 4,200 transactions.</span>
End of explanation
data = {'Transactions': [4181], 
        'Customers': [1000], 
        'MinTransactionDate': ['2010-01-04'],
        'MaxTransactionDate': ['2015-12-31'],
        'Amount': [33729.91]}
df = pd.DataFrame(data, index = [''])
df
TransactionsPerCustomer = round(Transactions / Customers, 2)
TransactionsPerCustomer
AmountPerTransaction = round(Amount / Transactions, 2)
AmountPerTransaction
AmountPerCustomer = round(Amount / Customers, 2)
AmountPerCustomer
Explanation: <span style="color:gray; font-family:Helvetica; font-size:1em;">As with any analysis, the first thing we’ll do is look at some basic summary statistics.</span>
End of explanation
data = {'TransactionsPerCustomer': [4.0], 
        'AmountPerTransaction': [8.07], 
        'AmountPerCustomer': [33.73]}
df = pd.DataFrame(data, index = [''])
df
more_summary = [TransactionsPerCustomer, AmountPerTransaction, AmountPerCustomer]
more_summary
Explanation: <span style="color:gray; font-family:Helvetica; font-size:1em;">Note that the data consists of 1000 customers who made transactions between 2010 and 2015. Furthermore, each customer made about 4 transactions for 8 bucks a piece, totaling close to $34. This amount can be considered a lower bound on CLV since it’s the total amount spent by each customer, but we still expect existing customers to make future purchases.</span>
End of explanation
data.loc[data['Amount'] >= 29.99]
import seaborn as sns
sns.set(color_codes=True)
Explanation: <span style="color:gray; font-family:Helvetica; font-size:1em;">We need to consider outlier transactions and should remove the transactions from the data entirely. Here we inspect the largest transactions.</span>
End of explanation
plt.title('Distribution of Transaction Amounts', fontsize=14, fontweight="bold")
sns.distplot(data.Amount, color='#3498db')
Explanation: <span style="color:black; font-family:Helvetica; font-size:2.5em;">Plotting Univariate Distributions</span>
<span style="color:gray; font-family:Helvetica; font-size:1em;">We could use a statistical test to check for outliers, but here it’s pretty clear that none exist.  Plotting the entire distribution of transaction amounts should give us more confidence in our assertion.</span>
End of explanation
<END_TASK>