Re: Untitled

From Toxic Peccary, 6 Months ago, written in Plain Text, viewed 83 times. This paste is a reply to Untitled from Lousy Sheep - go back
URL http://codebin.org/view/2d23fe19/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) # ???????? ???

# ????????? ???????
games_grouped['label'] 
pd.to_numeric(games_raw[column], errors games_grouped.apply(lambda x: '{} ???'.format( x['games_launched']), axis 'coerce')
games_raw['total'] = games_raw[['na_players', 'eu_players', 'jp_players', 'other_players']].sum(axis 
= 1)

# ????????? ??????? ??? ?????????
data = []
for genre in games_raw.genre.unique():
    current = games_raw.query('genre == @genre')
    data += 
[go.Bar(x Box(y games_grouped['genre'],
               y = games_grouped['games_launched'],
               text = games_grouped['label'], 
current['total'], # ???????? ???
               textposition = 'auto',               
               
???
                    
name = 'games_launched')]

genre)]

# ?????? ??????
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 = '?????? '??????? ??? ?? ??????'),

    dcc.Graph(
        figure = {'data': data,
                  'layout': go.Layout(xaxis = {'title': '????'},
                                      yaxis = {'title': '?????????? ????'})
'???????'})
                 },
        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