@digidickinson/

Rank UK petition signatures by constituency

Python

A script to take a petition, pull out the data for signature by constituency and sort highest to lowest number of sigs

fork
loading
Files
  • main.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.9563374797756266","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"aW1wb3J0IHJlcXVlc3RzCmltcG9ydCBwYW5kYXMgYXMgcGQKcmVzcG9uc2UgID0gcmVxdWVzdHMuZ2V0KCdodHRwczovL3BldGl0aW9uLnBhcmxpYW1lbnQudWsvcGV0aXRpb25zLzIzMzkyNi5qc29uJykKcGV0aXRpb25fZGF0YSA9IHJlc3BvbnNlLmpzb24oKQpjb25zdGl0dWVuY3lfZGF0YSA9IHBldGl0aW9uX2RhdGFbJ2RhdGEnXVsnYXR0cmlidXRlcyddWydzaWduYXR1cmVzX2J5X2NvbnN0aXR1ZW5jeSddCmNvbnN0aXR1ZW5jeV9kZiA9IHBkLkRhdGFGcmFtZShjb25zdGl0dWVuY3lfZGF0YSkKY29uc3RpdHVlbmN5X3JhbmsgPSBjb25zdGl0dWVuY3lfZGYuc29ydF92YWx1ZXMoYnk9WydzaWduYXR1cmVfY291bnQnXSwgYXNjZW5kaW5nPUZhbHNlKQpwcmludChjb25zdGl0dWVuY3lfcmFuayk="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
import requests
import pandas as pd
response  = requests.get('https://petition.parliament.uk/petitions/233926.json')
petition_data = response.json()
constituency_data = petition_data['data']['attributes']['signatures_by_constituency']
constituency_df = pd.DataFrame(constituency_data)
constituency_rank = constituency_df.sort_values(by=['signature_count'], ascending=False)
print(constituency_rank)