Tips on reshaping data, pivot-like?
You can pivot your data using crosstab, but as usual it requires a well-known column's name.

First you should install tablefunc module.

CREATE EXTENSION tablefunc;


Then you can call a crosstab with

SELECT * FROM 
  crosstab('SELECT rank, year::INT, COUNT(*)::INT ct FROM demo 
            GROUP BY 1, 2 ORDER BY 1, 2') 
  AS ct(rk INT, "2016" INT, "2017" INT)




rk | 2016 | 2017
-: | ---: | ---:
 1 |    1 |    4
 2 |    2 |    7
 3 |    8 |    7



dbfiddle here