image_output_1.png
import pandas as pd

df = pd.read_csv('../input/top-100-cryptocurrency-2022/Top 100 Cryptocurrency 2022.csv')

df.columns = ['ranking', 'name', 'price', 'changes_24h', 'changes_7d', 'changes_30d', 'changes_1y', 'market_cap', 'volume', 'supply']

df.shape

df.isnull().sum()

blacklist_index = df[~df.market_cap.str.contains('B|M|C')].index

market_cap = df.market_cap.drop(blacklist_index)

def market_cap_conv(price: str):
    sym_dict = {'B': 1000000000, 'M': 1000000, 'K': 1000}
    price, symbol = price.replace('$', '').split(' ')
    price = float(price)
    price *= sym_dict[symbol]
    return price

market_cap = market_cap.apply(market_cap_conv)

top_market_cap = pd.DataFrame(data={'name': df.name, 'market_cap': market_cap}).sort_values('market_cap', ascending=False)[1:21]

volume_cln_index = df[~df.volume.str.contains('B|M|K', regex=True)].index

df.loc[volume_cln_index, 'volume'] = df.volume[volume_cln_index].str.replace('$', '', regex=False) + 'M'

def volume_cap_conv(price: str):
    sym_dict = {'B': 1000000000, 'M': 1000000, 'K': 1000}
    price, symbol = price.replace('$', '').split(' ')[:2]
    price = float(price)
    price *= sym_dict[symbol]
    return price

df.volume = df.volume.apply(volume_cap_conv)

top_volume_coins = df.sort_values('volume', ascending=False)[:20]

df[['changes_24h', 'changes_7d', 'changes_30d', 'changes_1y']].apply(lambda col: ~col.str.contains('%')).sum()