image_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

TITLE_SIZE = 20
TITLE_PAD = 15
LABELE_SIZE = 15
LABELE_PAD = 10

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()

top_price_alts = df[['name', 'price']][3:23]

sns.set_theme()

fig, ax = plt.subplots(figsize=(11, 9))
sns.barplot(ax=ax, x='price', y='name', data=top_price_alts)

ax.set_title('Top 20 Altcoins by Price', fontsize=TITLE_SIZE, pad=TITLE_PAD)
ax.set_ylabel('Crypto Name', fontdict={'fontsize': LABELE_SIZE}, labelpad=LABELE_PAD)
ax.set_xlabel('Price', fontdict={'fontsize': LABELE_SIZE}, labelpad=LABELE_PAD)

plt.show()

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]

fig, ax = plt.subplots(figsize=(11, 8))

sns.barplot(ax=ax, x='market_cap', y='name', data=top_market_cap, palette='pastel')

ax.set_title('Top 20 Altcoins by Market Cap', fontsize=TITLE_SIZE, pad=TITLE_PAD)
ax.set_xlabel('Market Cap in bn', fontdict={'fontsize': LABELE_SIZE}, labelpad=LABELE_PAD)
ax.set_ylabel('Crypto Name', fontdict={'fontsize': LABELE_SIZE}, labelpad=LABELE_PAD)
ax.xaxis.set_major_formatter(lambda x, pos: f'{int(x)/1_000_000_000}B')

plt.show()

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]

fig, ax = plt.subplots(figsize=(11, 8))
palette = sns.color_palette('husl', 6)
sns.barplot(ax=ax, x='volume', y='name', data=top_volume_coins, palette=palette)
ax.set_title('Top 20 Coins by Volume 24H', fontsize=TITLE_SIZE, pad=TITLE_PAD)
ax.set_xlabel('Volume', fontdict={'fontsize': LABELE_SIZE}, labelpad=LABELE_PAD)
ax.set_ylabel('Crypto Name', fontdict={'fontsize': LABELE_SIZE}, labelpad=LABELE_PAD)
ax.xaxis.set_major_formatter(lambda x, pos: f'{float(x) / 1000000000}B')
plt.show()