image_output_1.png
import matplotlib.pyplot as plt

import numpy as np # linear algebra

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

people = pd.read_csv('../input/people.csv', dtype={'people_id': np.str, 'activity_id': np.str, 'char_38': np.int32}, parse_dates=['date'])
act_train = pd.read_csv('../input/act_train.csv', dtype={'people_id': np.str, 'activity_id': np.str, 'otcome': np.int8}, parse_dates=['date'])
act_test = pd.read_csv('../input/act_test.csv', dtype={'people_id': np.str, 'activity_id': np.str, 'otcome': np.int8}, parse_dates=['date'])

act_train['date'].groupby(act_train.date.dt.date).count().plot(figsize=(10, 5), label='Train')
act_test['date'].groupby(act_test.date.dt.date).count().plot(figsize=(10, 5), label='Test')

positive_counts = pd.DataFrame({'positive_counts': act_train[act_train['outcome'] == 1].groupby('people_id', as_index=True).size()}).reset_index()
negative_counts = pd.DataFrame({'negative_counts': act_train[act_train['outcome'] == 0].groupby('people_id', as_index=True).size()}).reset_index()
hstry = positive_counts.merge(negative_counts, on='people_id', how='outer')
hstry['positive_counts'] = hstry['positive_counts'].fillna('0').astype(np.int64)
hstry['negative_counts'] = hstry['negative_counts'].fillna('0').astype(np.int64)
hstry['profit'] = hstry['positive_counts'] - hstry['negative_counts']

hstry.sort_values(by='positive_counts', ascending=False).head(10)

hstry.sort_values(by='negative_counts', ascending=False).head(10)

hstry['profit'].describe()