Package: pychadwick
pychadwickA Python package to interface with theChadwicklibray.Chadwickis a set of tools for parsing retrosheet data
and is available athttp://chadwick.sourceforge.net/doc/index.htmlhttps://github.com/chadwickbureau/chadwickFeaturesAs of now this package supports retrosheet event data only.Installation$pipinstallpychadwickExample usePython replacement for cweventWhen you installpychadwick, it will install a
Python exe that mimic thecweventexe from the
chadwick project. It reads a set of event files and
prints them out in csv format tostdout.This downloads a fresh copy of the retrosheet event files,
and parses them with 7 CPUs$timepycwevent-n7>/tmp/events1.csv
stderr:data_rootnotgivenasargument,downloadingfreshcopyofretrosheetevents...
stderr:found2254files
Warning:Invalidintegervalue'b'real3m14.517s
user12m18.104s
sys0m25.264s

$wc-l/tmp/events1.csv13976191/tmp/events1.csvThis uses a pre-downloaded copy of the retrosheet event files,
with 7 CPUs$timepycwevent-n7--data-root/tmp/retrosheet-master/event/regular/>/tmp/events2.csv
stderr:found2254files
Warning:Invalidintegervalue'b'real1m57.499s
user9m52.236s
sys0m17.672s

$wc-l/tmp/events2.csv13976184/tmp/events2.csvPython interface to cweventLoad eventsLoad events for a game from a file stored on the web>>>frompychadwick.chadwickimportChadwick>>>chadwick=Chadwick()>>>file_path="https://raw.githubusercontent.com/chadwickbureau/retrosheet/master/event/regular/1982OAK.EVA">>>games=chadwick.games(file_path)>>>game=next(games)>>>df=chadwick.game_to_dataframe(game)>>>dfGAME_IDAWAY_TEAM_IDINN_CTBAT_HOME_ID...ASS9_FLD_CDASS10_FLD_CDUNKNOWN_OUT_EXC_FLUNCERTAIN_PLAY_EXC_FL0OAK198204060CAL10...00FF1OAK198204060CAL10...00FF2OAK198204060CAL10...00FF3OAK198204060CAL11...00FF4OAK198204060CAL11...00FF.............................81OAK198204060CAL111...00FF82OAK198204060CAL111...00FF83OAK198204060CAL111...00FF84OAK198204060CAL111...00FF85OAK198204060CAL111...00FF[86rowsx159columns]Load events for a game from a local file>>>file_path=" /tmp/retrosheet-master/event/regular/1982OAK.EVA">>>games=chadwick.games(file_path)>>>game=next(games)>>>df=chadwick.game_to_dataframe(game)>>>dfGAME_IDAWAY_TEAM_IDINN_CTBAT_HOME_ID...ASS9_FLD_CDASS10_FLD_CDUNKNOWN_OUT_EXC_FLUNCERTAIN_PLAY_EXC_FL0OAK198204060CAL10...00FF1OAK198204060CAL10...00FF2OAK198204060CAL10...00FF3OAK198204060CAL11...00FF4OAK198204060CAL11...00FF.............................81OAK198204060CAL111...00FF82OAK198204060CAL111...00FF83OAK198204060CAL111...00FF84OAK198204060CAL111...00FF85OAK198204060CAL111...00FF[86rowsx159columns]Check which columns are defined>>>chadwick.all_headersCheck which columns are enabled>>>chadwick.active_headersDisable all columns, and add onlyGAME_IDandBAT_ID>>>_=[chadwick.unset_event_field(e)foreinchadwick.all_headers]>>>chadwick.active_headers[]>>>chadwick.set_event_field("GAME_ID")>>>chadwick.set_event_field("BAT_ID")>>>games=chadwick.games(file_path)>>>game=next(games)>>>df=chadwick.game_to_dataframe(game)>>>dfGAME_IDBAT_ID0OAK198204060burlr0011OAK198204060lynnf0012OAK198204060carer0013OAK198204060hendr0014OAK198204060murpd002........81OAK198204060meyed00182OAK198204060armat00183OAK198204060grosw00184OAK198204060spenj10185OAK198204060loped001[86rowsx2columns]Activate all the columns again>>>chadwick.set_all_headers()