text_plain_output_1.png image_output_1.png
import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import pandas as pd
import numpy as np
import seaborn as sns
import time, warnings
import datetime as dt
import squarify
import matplotlib.pyplot as plt
warnings.filterwarnings('ignore')
df = pd.read_csv('../input/customer-trans/data.csv', encoding='ISO-8859-1', dtype={'CustomerID': str, 'InvoiceNo': str})
df.shape

df = df[df['Country'] == 'Germany']

df['Value'] = df['Quantity'] * df['UnitPrice']
df['InvoiceDate'] = pd.DatetimeIndex(df['InvoiceDate']).date

rfm = df.groupby('CustomerID', as_index=False).agg(Recent_date=('InvoiceDate', 'max'), Frequency=('InvoiceNo', 'count'), Monetory=('Value', 'sum'))
rfm.head()