BG Vote algorithm
tanchomihov
python
10 months ago
1.1 kB
39
Indexable
import pandas as pd import numpy as np # Party names and total number of deputies parties = ["GERB-SDS", "DPS", "PP-DB", "Vazrajd.", "BSP", "ITN", "Velichie"] num_deputies = 240 # Ensure GERB-SDS and DPS have the highest and second highest number of deputies gerb_deputies = np.random.randint(80, 100) dps_deputies = np.random.randint(60, 80) # Remaining deputies to be allocated to the other parties remaining_deputies = num_deputies - gerb_deputies - dps_deputies # Randomly allocate remaining deputies to other parties (excluding GERB-SDS and DPS) other_deputies_allocation = np.random.multinomial(remaining_deputies, np.ones(len(parties) - 2) / (len(parties) - 2)) # Combine the allocations deputies_allocation = np.concatenate(([gerb_deputies, dps_deputies], other_deputies_allocation)) # Create a DataFrame df = pd.DataFrame({ "Number": range(1, len(parties) + 1), "Party": parties, "Deputies": deputies_allocation }) # Sort the DataFrame by the number of deputies in descending order df_sorted = df.sort_values(by="Deputies", ascending=False).reset_index(drop=True) # Display the DataFrame print(df_sorted)
Editor is loading...
Leave a Comment