嗨!
使用 chess.pgn 将国际象棋数据库转换为数据框,要从数据库中读取第 n 个游戏,我需要先读取所有以前的游戏吗?我不能直接跳到游戏n?如果我想将处理分布在一个有 10^8 场比赛的数据库中,我无法在第 9e7 场比赛中开始阅读?
import pandas as pd
import chess.pgn
from datetime import datetime as dt
import os
import glob
nome_arquivo = "Analises_01.pgn"
inicio = 0
numero_jogos = 1.47e8
arquivo = open(nome_arquivo, encoding="utf8")
ratings = []
for j in range(numero_jogos):
first_game = chess.pgn.read_game(arquivo)
if j >= inicio:
try:
Brancas = int(first_game.headers["WhiteElo"])
Pretas = int(first_game.headers["BlackElo"])
ratings.append([Brancas, Pretas])
except:
pass