# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + id="YoyUjwugZb0k"
import pandas as pd
import numpy as np
import requests
import matplotlib.pyplot as plt
import json

# + id="snarO45jkACD"
response = pd.read_json('https://api.atlasacademy.io/export/JP/nice_servant_lore_lang_en.json')

# + colab={"base_uri": "https://localhost:8080/"} id="Rtma-0B1kJ1S" outputId="a54f5b55-7faf-443b-9504-59c29ffc8705"
print(response)

# + colab={"base_uri": "https://localhost:8080/"} id="IpgfwW1YkXdG" outputId="87a0aeb8-d4ad-4d89-c5f9-36d6296afffe"
response.columns

# + colab={"base_uri": "https://localhost:8080/", "height": 819} id="1g2_DzGokdEU" outputId="ca4e0ef3-805f-43d7-dffb-4215bf34527f"
response.head()

# + id="841FyIIKkmMf" colab={"base_uri": "https://localhost:8080/", "height": 392} outputId="c737a99a-9bf7-48ed-ecac-8fa9c72c4a28"
response.rarity.value_counts().plot(kind='barh', figsize=(8, 6) )

# + colab={"base_uri": "https://localhost:8080/"} id="jvZk2siYoKrt" outputId="02dd27bc-dfcd-4387-9dac-b06cded5d988"
response.rarity.value_counts()

# + colab={"base_uri": "https://localhost:8080/"} id="v8j8fr7Mo5Yd" outputId="bc238a88-a223-4ccb-cedd-4bccc81cb2fe"
response.rarity.count()

# + colab={"base_uri": "https://localhost:8080/", "height": 1000} id="ybziU0CMp7eB" outputId="93ffc12f-e71f-4a86-c374-9907ee6ad31c"
response.pivot_table(index=['rarity', 'className'], aggfunc=lambda x: len(x.unique()))

# + id="0gqi4OC4qLw_"
df1 = response[['rarity', 'className', 'collectionNo']]
df_pivot = df1.pivot_table(index=['rarity', 'className'], aggfunc=lambda x: len(x.unique()))

# + colab={"base_uri": "https://localhost:8080/", "height": 1000} id="FYh6mNQztROt" outputId="07db6ba7-e9a4-49ed-bad6-2101d606f9ef"
fig = df_pivot.plot(kind='barh', figsize=(15, 18), grid = 'True')

# plt.rcParams['figure.facecolor'] = "white"
fig.figure.savefig('distribution.png', transparent=False)

# + colab={"base_uri": "https://localhost:8080/"} id="nHHURotGuNsR" outputId="aae0364f-67cb-424e-c52b-1c76fe627438"
df_pivot.columns

# + colab={"base_uri": "https://localhost:8080/"} id="MeYp8_qZwOT-" outputId="dd84326f-209b-42ff-8b97-4e73d7ca0f0f"
df1.rarity.describe()

# + colab={"base_uri": "https://localhost:8080/"} id="Mf1T45J9wwd2" outputId="858c189a-6ac3-40ed-b522-b0b004b44b2c"
df1.className.value_counts()

# + colab={"base_uri": "https://localhost:8080/"} id="ppfzWrKP6bju" outputId="d69cfc05-696f-42d4-e900-f34c938adcc5"
df1.rarity.value_counts()

# + id="lq0ke54l7J_J" colab={"base_uri": "https://localhost:8080/", "height": 1000} outputId="3a5d772b-a075-4031-c9d2-2c15683913d7"
df_pivot

# + id="zUZ5ee6NFd35"
df_pivot.to_csv('distribution.csv')

StarcoderdataJupyterScriptsDedupFiltered