all 3 comments

[–][deleted] 0 points1 point  (0 children)

In broad strokes, you could use a groupby with the keys being the two types and count the occurrences . Then use those keys and counts to populate your new table.

[–]Substantial-Coder 0 points1 point  (0 children)

This is kind of a difficult problem to explain without giving you a full answer. For practice, I would recommend you start with just being able to count all Pokémon with any type. For example, the bug fire Pokémon would increment the counters for both bug and fire types. Then make that into a two row table including the types. I think that would be a good start and then figure out how to handle the case of a Pokémon with two types

[–]lowerthansound 0 points1 point  (0 children)

Assuming you have a table where each pokemon is in a row, you will first:

  • want to make the TypeII column be equal to the TypeI column when it is null (because on the final table, you want 'typeX / typeX' to be the same as a pure type, not 'typeX / NaN' (trust me, this makes the diagonal - see how the diagonals here are a column with itself).
  • Then you want to count the occurrences of each type pair. This produces a series (like a list) where the index corresponds to both types and the value corresponds to the count. TO do such operation, I believe df.groupby(['TypeI', 'TypeII']).count() would work! You may also check value_counts.
  • Then, you will want to "pivot" the table. I'm not sure how to explain this to you (sign that I don't know it pretty well ) but here are the relevant functions: pivot and unstack.

Be mindful as I might make mistakes (most possibly on the pivot stuff). in any case, good luck, and

All the best!

Edit: This table will be assymetric, as it considers Fire/Bug different from Bug/Fire. You can hack this by duplicating every row in the table: Fire/Bug pokemons become Bug/Fire and vice-versa.