Try to implement the privote_table of pandas to produce a table for each of party and each state shows how much the party receievd in total contributions from the state.
Is this the right way to do or i has to get into the data base and get fectched out. However the code below gives error.
party_and_state = candidates.merge(contributors, on='id')
party_and_state.pivot_table(df,index=["party","state"],values=["amount"],aggfunc=[np.sum])
The expected result could be something like the table below. The first coulmn is the state name then the party D underneath the party D is the total votes from each state, the same applies with the party R
+-----------------+---------+--------+
|     state       | D       | R      |
+-----------------+---------+--------+
|      AK         | 500     | 900    |
|      IL         | 600     | 877    |
|      FL         | 200     | 400    |
|      UT         | 300     | 300    |
|      CA         | 109     | 90     |
|      MN         | 800     | 888    |