# ---
# 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
# ---

# +
# %matplotlib inline

import warnings
import os
from pathlib import Path
import numpy as np
import pandas as pd

import matplotlib.pyplot as plt
import seaborn as sns
# -

warnings.filterwarnings('ignore')
plt.style.use('ggplot')
np.random.seed(42)

# ## Clean Marketcap info

with pd.HDFStore('../../data/assets.h5') as store:
    stocks = store['us_equities/stocks']

stocks.info()

stocks.head()

stocks = stocks[stocks.marketcap.notnull() & stocks.marketcap.str[-1].isin(['M', 'B'])]
stocks.marketcap = stocks.marketcap.str.replace('$', '')

stocks.marketcap.head()

for s, val in {'M': 1e6, 'B': 1e9}.items():
    stocks.loc[stocks.marketcap.str[-1] == s, 'marketcap'] = (stocks
                                                              .loc[stocks.marketcap.str[-1] == s, 'marketcap']
                                                              .str.replace(s, '')
                                                              .apply(pd.to_numeric)
                                                              .mul(val)
                                                              .astype(int))

sns.distplot(np.log(stocks.marketcap));

marketcap = stocks['marketcap']

with pd.HDFStore('../../data/assets.h5') as store:
    stocks = store['us_equities/stocks'].assign(marketcap=marketcap)
    store.put('us_equities/stocks', stocks)



StarcoderdataJupyterScriptsDedupFiltered