image_output_1.png
from scipy.stats import pearsonr

import matplotlib.pyplot as plt

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

import seaborn as sns

train = pd.read_csv('../input/tabular-playground-series-sep-2022/train.csv', index_col='row_id')
test = pd.read_csv('../input/tabular-playground-series-sep-2022/test.csv', index_col='row_id')

train.dtypes

train.nunique()

plt.figure(figsize=(16,5))
ax = sns.barplot(data=train, x='product', y='num_sold', hue='country')
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
plt.title('Product distribution grouped by country')
plt.show()

store_corr = pearsonr(train.loc[train['store'] == 'KaggleMart', 'num_sold'], train.loc[train['store'] == 'KaggleRama', 'num_sold'])[0]
print(f'Store correlation: {store_corr:.4f}')
mult_factor = train.loc[train['store'] == 'KaggleMart', 'num_sold'].sum() / train.loc[train['store'] == 'KaggleRama', 'num_sold'].sum()
print(f'Multiplicative factor: {mult_factor:.4f}')