Examples The examples/ directory in the repository contains a number of ready-to-run scripts and notebooks.
Table of contents Scripts Jupyter Notebooks Quick Example: List Councillors Quick Example: Search Speeches Quick Example: Query the Gever Backend Quick Example: Plot Voting Results Scripts Jupyter Notebooks Quick Example: List Councillors import swissparlpy as spp
councillors = spp . get_data ( 'MemberCouncil' , Language = 'DE' , CantonAbbreviation = 'ZH' )
for c in councillors :
print ( f " { c [ 'FirstName' ] } { c [ 'LastName' ] } " )
Quick Example: Search Speeches import swissparlpy as spp
opd_client = spp . SwissParlClient ( backend = "openparldata" )
response = opd_client . get_data (
"speeches" ,
search_mode = "natural" ,
search_scope = "all" ,
search_language = "de" ,
search = "Klimawandel"
)
df = response . to_dataframe ()
print ( df [[ "id" , "date_start" , "text_content_de" ]]. head ())
Quick Example: Query the Gever Backend import swissparlpy as spp
# Electoral districts of the canton of Zurich
districts = spp . get_data ( 'wahlkreise' , 'inaktiv = false' , backend = 'gever' )
for d in districts [: 5 ]:
print ( d [ 'name' ])
# Search for a member and explode their mandates into a DataFrame
members = spp . get_data ( 'mitglieder' , name = 'Marti' , backend = 'gever' )
mandates = members . explode ( 'behoerdenmandate' )
print ( mandates . head ())
Quick Example: Plot Voting Results import swissparlpy as spp
import matplotlib.pyplot as plt
votes = spp . get_data ( 'Voting' , Language = 'DE' , IdVote = 23458 )
spp . plot_voting ( votes , theme = 'scoreboard' , result = True )
plt . show ()