Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 49 additions & 35 deletions app_6_eda_cryptocurrency/crypto-price-app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
st.title('Crypto Price App')
st.markdown("""
This app retrieves cryptocurrency prices for the top 100 cryptocurrency from the **CoinMarketCap**!

""")
#---------------------------------#
# About
Expand All @@ -42,7 +41,7 @@
# Page layout (continued)
## Divide page to 3 columns (col1 = sidebar, col2 and col3 = page contents)
col1 = st.sidebar
col2, col3 = st.beta_columns((2,1))
col2, col3 = st.beta_columns((3,1))

#---------------------------------#
# Sidebar + Main panel
Expand All @@ -62,7 +61,7 @@ def load_data():
coin_data = json.loads(data.contents[0])
listings = coin_data['props']['initialState']['cryptocurrency']['listingLatest']['data']
for i in listings:
coins[str(i['id'])] = i['slug']
coins[str(i['id'])] = i['slug']

coin_name = []
coin_symbol = []
Expand All @@ -74,14 +73,14 @@ def load_data():
volume_24h = []

for i in listings:
coin_name.append(i['slug'])
coin_symbol.append(i['symbol'])
price.append(i['quote'][currency_price_unit]['price'])
percent_change_1h.append(i['quote'][currency_price_unit]['percent_change_1h'])
percent_change_24h.append(i['quote'][currency_price_unit]['percent_change_24h'])
percent_change_7d.append(i['quote'][currency_price_unit]['percent_change_7d'])
market_cap.append(i['quote'][currency_price_unit]['market_cap'])
volume_24h.append(i['quote'][currency_price_unit]['volume_24h'])
coin_name.append(i['slug'])
coin_symbol.append(i['symbol'])
price.append(i['quote'][currency_price_unit]['price'])
percent_change_1h.append(i['quote'][currency_price_unit]['percentChange1h'])
percent_change_24h.append(i['quote'][currency_price_unit]['percentChange24h'])
percent_change_7d.append(i['quote'][currency_price_unit]['percentChange7d'])
market_cap.append(i['quote'][currency_price_unit]['marketCap'])
volume_24h.append(i['quote'][currency_price_unit]['volume24h'])

df = pd.DataFrame(columns=['coin_name', 'coin_symbol', 'market_cap', 'percent_change_1h', 'percent_change_24h', 'percent_change_7d', 'price', 'volume_24h'])
df['coin_name'] = coin_name
Expand All @@ -100,15 +99,14 @@ def load_data():
sorted_coin = sorted( df['coin_symbol'] )
selected_coin = col1.multiselect('Cryptocurrency', sorted_coin, sorted_coin)

df_selected_coin = df[ (df['coin_symbol'].isin(selected_coin)) ] # Filtering data
df_selected_coin = df[(df['coin_symbol'].isin(selected_coin))] # Filtering data

## Sidebar - Number of coins to display
num_coin = col1.slider('Display Top N Coins', 1, 100, 100)
df_coins = df_selected_coin[:num_coin]

## Sidebar - Percent change timeframe
percent_timeframe = col1.selectbox('Percent change time frame',
['7d','24h', '1h'])
percent_timeframe = col1.selectbox('Percent change time frame', ['7d','24h', '1h'])
percent_dict = {"7d":'percent_change_7d',"24h":'percent_change_24h',"1h":'percent_change_1h'}
selected_percent_timeframe = percent_dict[percent_timeframe]

Expand Down Expand Up @@ -144,26 +142,42 @@ def filedownload(df):
col3.subheader('Bar plot of % Price Change')

if percent_timeframe == '7d':
if sort_values == 'Yes':
df_change = df_change.sort_values(by=['percent_change_7d'])
col3.write('*7 days period*')
plt.figure(figsize=(5,25))
plt.subplots_adjust(top = 1, bottom = 0)
df_change['percent_change_7d'].plot(kind='barh', color=df_change.positive_percent_change_7d.map({True: 'g', False: 'r'}))
col3.pyplot(plt)
if len(selected_coin) !=0:
if sort_values == 'Yes':
df_change = df_change.sort_values(by=['percent_change_7d'])
col3.write('*7 days period*')
plt.figure(figsize=(5,25))
plt.subplots_adjust(top = 1, bottom = 0)
df_change['percent_change_7d'].plot(kind='barh', color=df_change.positive_percent_change_7d.map({True: 'g', False: 'r'}))
col3.pyplot(plt)

else:
col3.markdown("""
Select some cryptocurrencies to plot.
""")
elif percent_timeframe == '24h':
if sort_values == 'Yes':
df_change = df_change.sort_values(by=['percent_change_24h'])
col3.write('*24 hour period*')
plt.figure(figsize=(5,25))
plt.subplots_adjust(top = 1, bottom = 0)
df_change['percent_change_24h'].plot(kind='barh', color=df_change.positive_percent_change_24h.map({True: 'g', False: 'r'}))
col3.pyplot(plt)
if len(selected_coin) !=0:
if sort_values == 'Yes':
df_change = df_change.sort_values(by=['percent_change_24h'])
col3.write('*24 hour period*')
plt.figure(figsize=(5,25))
plt.subplots_adjust(top = 1, bottom = 0)
df_change['percent_change_24h'].plot(kind='barh', color=df_change.positive_percent_change_24h.map({True: 'g', False: 'r'}))
col3.pyplot(plt)
else:
col3.markdown("""
Select some cryptocurrencies to plot.
""")
else:
if sort_values == 'Yes':
df_change = df_change.sort_values(by=['percent_change_1h'])
col3.write('*1 hour period*')
plt.figure(figsize=(5,25))
plt.subplots_adjust(top = 1, bottom = 0)
df_change['percent_change_1h'].plot(kind='barh', color=df_change.positive_percent_change_1h.map({True: 'g', False: 'r'}))
col3.pyplot(plt)
if len(selected_coin) !=0:
if sort_values == 'Yes':
df_change = df_change.sort_values(by=['percent_change_1h'])
col3.write('*1 hour period*')
plt.figure(figsize=(5,25))
plt.subplots_adjust(top = 1, bottom = 0)
df_change['percent_change_1h'].plot(kind='barh', color=df_change.positive_percent_change_1h.map({True: 'g', False: 'r'}))
col3.pyplot(plt)
else:
col3.markdown("""
Select some cryptocurrencies to plot.
""")