Re: Untitled

From Lousy Kitten, 6 Months ago, written in Plain Text, viewed 100 times. This paste is a reply to Untitled from Lousy Sheep - go back
URL http://codebin.org/view/622f7cbc/diff Embed
Viewing differences between Untitled and Re: Untitled
#!/usr/bin/python
# -*- coding: utf-8 -*-

import dash
import dash_core_components as dcc
import dash_html_components as html

import plotly.graph_objs as go

import pandas as pd



# ?????? ?????? ??? ?????????
from sqlalchemy import create_engine

# ?????? ??????????? ? ???? ?????? ??? Postresql
#db_config = {'user': 'my_user',
#             'pwd': 'my_user_password',
#             'host': 'localhost',
#             'port': 5432,
#             'db': 'games'}
#engine = create_engine('postgresql://{}:{}@{}:{}/{}'.format(db_config['user'],
#                                                            db_config['pwd'],
#                                                            db_config['host'],
#                                                            db_config['port'],
#                                                            db_config['db']))
# ?????? ??????????? ? ???? ?????? ??? Sqlite
engine = create_engine('sqlite:////db/games.db', echo = False)

# ???????? ????? ??????
query = '''
            SELECT * FROM data_raw
        '''
games_raw = pd.io.sql.read_sql(query, con = engine)

????????? ?????? ??? ??????
games_grouped 
??????????? ????
games_raw['year_of_release'] 
(games_raw.groupby(['genre'])
                          .agg({'name': 'nunique'})
                          .rename(columns 
pd.to_datetime(games_raw['year_of_release'])
columns 
{'name': 'games_launched'})
                          .reset_index()
                )
games_grouped 
['na_players', 'eu_players', 'jp_players', 'other_players']
for column in columns: games_raw[column] 
games_grouped.sort_values(by='games_launched',ascending=False) pd.to_numeric(games_raw[column], errors = 'coerce')
games_raw['total'] = games_raw[['na_players',
                                'eu_players',
                                'jp_players',
                                'other_players']].sum(axis = 1).round(2)

???????? ???

# ????????? ???????
games_grouped['label'] = games_grouped.apply(lambda x: '{} ???'.format( x['games_launched']), axis = 1)

# ????????? 
??????????? ??????? ??? ?????????
games_raw = games_raw[['name', 'platform', 'genre', 'total']].sort_values(by = 'total', ascending = False).head(10)  # ???????? ???

data = [go.Bar(x Table(header games_grouped['genre'],
               y 
{'values': ['<b>????</b>', '<b>?????????</b>',
                                      '<b>????</b>', '<b>??????? ?? ???? ????????</b>'],
                           'fill_color': 'lightgrey',
                           'align': 'center'},
                 cells 
games_grouped['games_launched'],
               text = games_grouped['label'], 
{'values': games_raw.T.values})] # ???????? ???
               textposition = 'auto',               
               name = 'games_launched')]

???

# ?????? ??????
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets,compress=False)
app.layout = html.Div(children=[  
    
    # ????????? ????????? ????? HTML
    html.H1(children = '?????? '???-10 ??? ?? ??????'),

????????'),

    dcc.Graph(
        figure = {'data': data,
                  'layout': go.Layout(xaxis = {'title': '????'},
                                      yaxis = {'title': '?????????? ????'})
Layout()
                 },
        id = 'launches_by_genre' 'games_by_genre' # ???????? ???
    ),         
 
])

# ????????? ?????? ????????
if __name__ == '__main__':
    app.run_server(host='0.0.0.0', port=3000)

Reply to "Re: Untitled"

Here you can reply to the paste above