image_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

pd.set_option('display.max_rows', 10)
pd.set_option('display.max_columns', 10)

games = pd.read_csv('../input/chess-games/games.csv')

games.columns

games.loc[:, 'first_move'] = games.moves.map(lambda x: x.split(' ')[0])

chosen_cols = ['winner', 'increment_code', 'white_rating', 'black_rating', 'opening_name', 'first_move']

increment_code_values = ['10+0', '15+0', '15+15']
rapid_games = games[games.increment_code.isin(increment_code_values)][chosen_cols]
rapid_games.set_index('opening_name', inplace=True)

appearances = rapid_games.groupby('opening_name').winner.count().rename('appearances')
rapid_games = rapid_games.merge(appearances, how='left', on='opening_name')

chosen_openings = rapid_games[rapid_games.appearances >= 20].index.unique()

chosen_games = rapid_games[rapid_games.appearances >= 20]
chosen_games

win_rate_all = rapid_games.winner.value_counts(normalize=True) * 100

fig, ax = plt.subplots(figsize=(10, 6))
patches, texts, pcts = ax.pie(x=win_rate_all, labels=win_rate_all.index, autopct='%.1f', wedgeprops={'linewidth': 3.0, 'edgecolor': 'white'}, startangle=90, counterclock=False)
for i, patch in enumerate(patches):
    texts[i].set_color(patch.get_facecolor())
plt.setp(pcts, color='white')
plt.setp(texts, fontweight=600)
ax.set_title('General win rate', fontsize=18)
plt.tight_layout()
plt.show()