Skip to main content

Transforms a chess pgn file into a csv dataset containing game information and move information

Project description

pgn2data

This library converts chess pgn files into CSV tabulated data sets.

A pgn file can contain one or multiple chess games. The library parses the pgn file and creates two csv files:

  • Games file: contains high level information (e.g. date, site, event, score, players etc...)

  • Moves file: contains the moves for each game (e.g. notation, squares, fen position, is in check etc...)

The two files can be mapped together using a GUID which the process inserts into both files.

Installation

The library requires Python 3.7 or later.

To install, type the following command on the python terminal:

pip install pgn2data

Implementation

Here is a basic example of how to convert a PGN file:

from converter.pgn_data import PGNData

pgn_data = PGNData("tal_bronstein_1982.pgn")
result = pgn_data.export()
result.print_summary()

The return value from the export function allows you to check whether the datasets have been created or not.

To group multiple files into the same output file you can do the following:

pgn_data = PGNData(["file1.pgn","file2.pgn"],"output")
result = pgn_data.export()
result.print_summary()

The above code will process the two pgn files (file1 and file2) and export them to a file called "output.csv".

Examples

The folder 'samples' in this repository, has some examples of the output from the library.

You can also go here to see a Kaggle project that converted all of Magnus Carlsen's online Bullet games into CSV format.

Columns

This is a full list of the columns in each output file:

Games File

Field Description
game_id ID of game generated by process
game_order Order of game in PGN file
event Event
site Site
date_played Date played
round Round
white White player
black Black player
result Result
white_elo White player rating
white_rating_diff White rating difference from Black
black_elo Black player rating
black_rating_diff Black rating difference from White
white_title Player title
black_title Player title
winner Player name
winner_elo Player rating
loser Losing player
loser_elo Player rating
winner_loser_elo_diff Diff in rating
eco Opening
termination How game ended
time_control Time control
utc_date Date played
utc_time Time played
variant Game type
ply_count Ply Count
date_created Extract date
file_name PGN source file

Moves File

Field Description
game_id ID of game that maps to games file
move_no Order of moves
move_no_pair Chess move number
player Player name
notation Standard notation of move
move Before and after piece location
from_square Piece location before
to_square Piece location after
piece Initial of piece name
color Piece color
fen Fen position
is_check Is check on board
is_check_mate Is checkmate on board
is_fifty_moves Is 50 move complete
is_fivefold_repetition Is 5 fold reptition on board
is_game_over Is game over
is_insufficient_material Is game over from lack of mating material
white_count Count of white pieces
black_count Count of black pieces
white_{piece}_count Count of white specifed piece
black_{piece}_count Count of black specifed piece
captured_score_for_white Total of black pieces captured
captured_score_for_black Total of white pieces captured
fen_row{number}_{colour)_count Number of pieces for the specified colour on this row of the board
fen_row{number}_{colour}_value Total value of pieces for the specified colour on this row of the board
move_sequence Sequence of moves upto current position

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pgn2data-0.0.5.tar.gz (27.3 kB view details)

Uploaded Source

Built Distribution

pgn2data-0.0.5-py3-none-any.whl (27.9 kB view details)

Uploaded Python 3

File details

Details for the file pgn2data-0.0.5.tar.gz.

File metadata

  • Download URL: pgn2data-0.0.5.tar.gz
  • Upload date:
  • Size: 27.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.2

File hashes

Hashes for pgn2data-0.0.5.tar.gz
Algorithm Hash digest
SHA256 5bf56b0d0816e43b0657a81eff417c0aa09093abe6cec2b33a07b492c306174f
MD5 44994a1e7a082dc110846ac58f096c61
BLAKE2b-256 1408d1fc2815eb3d2e97803c1a8a972cf84a710ecbfa1e191c5f75e7bf9e8a6f

See more details on using hashes here.

File details

Details for the file pgn2data-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: pgn2data-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 27.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.2

File hashes

Hashes for pgn2data-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 8c04b6f550d860801908c05a7a5da7b8898cfec97bf9c85b1faf32c893db8157
MD5 66763e11548b569c7765ac3d3740a623
BLAKE2b-256 82c5a1466fd170a02f2e8d525595a05a6314faa17335bcd69b325160e35f7706

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page