# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
import pandas as pd
import os

current_dir = os.getcwd()
train_path = os.path.join(current_dir, os.pardir, 'data', 'raw', 'train.csv') 
# -

df = pd.read_csv(train_path)
df.head()

len(df)

len(df.dropna())

df['first_active_month'] = pd.to_datetime(df['first_active_month'], format='%Y-%m')

df['first_active_month'].min()

df['first_active_month'].max()

# +
# %matplotlib inline

import matplotlib
import matplotlib.pyplot as plt

def plot_counts(df, by, column):
    plt.plot(df.groupby([by]).count()[column])


# -

plot_counts(df,'first_active_month','card_id')

df.feature_1.value_counts().plot(kind='bar')

df.feature_2.value_counts().plot(kind='bar')

df.feature_3.value_counts().plot(kind='bar')

historical_path = os.path.join(current_dir, os.pardir, 'data', 'raw', 'historical_transactions.csv')
hist_trans = pd.read_csv(historical_path)

hist_trans.head()

len(hist_trans)

hist_trans['authorized_flag'].value_counts().plot(kind='bar')

hist_trans['card_id'].nunique()

df['card_id'].nunique()

df[~df.card_id.isin(hist_trans['card_id'])] 

hist_trans['city_id'].nunique()

hist_trans.category_1.unique()
hist_trans['category_1'].value_counts().plot(kind='bar')

install_counts = hist_trans[(hist_trans.installments < 999)].groupby(['installments']).count()['card_id']
plt.plot(install_counts)

hist_trans.installments.unique()

hist_trans.category_2.unique()
hist_trans['category_2'].value_counts().plot(kind='bar')

hist_trans.category_3.unique()
hist_trans['category_3'].value_counts().plot(kind='bar')

hist_trans.merchant_category_id.nunique()

hist_trans['state_id'].value_counts().plot(kind='bar')

hist_trans['month_lag'].value_counts().plot(kind='bar')

hist_trans['purchase_date'].dtype

dates = pd.to_datetime(hist_trans['purchase_date'])

hist_trans['purchase_month'] = dates.dt.to_period('M')
hist_trans['purchase_month'].value_counts().plot(kind='bar')

# +
new_merch_path = os.path.join(current_dir, os.pardir, 'data', 'raw', 'new_merchant_transactions.csv') 

new_merch = pd.read_csv(new_merch_path)
# -

new_merch.head()

new_merch[~new_merch.card_id.isin(hist_trans['card_id'])] 

new_merch[~new_merch.merchant_id.isin(hist_trans['merchant_id'])] 



StarcoderdataJupyterScriptsDedupFiltered