0

I need to convert this set of data [bigquery response]:

country     metric  quarter
Argentina   34174   1
Argentina   83961   2
Argentina   96373   3
Argentina   103782  4
Chile       7636    1
Chile       23434   2
Chile       19103   3
Chile       21729   4

to this:

Quarter Argentina   Chile
1       83961       19103
2       96373       21729
3       103782      23434
4       34174       7636

I use AppEngine[python]. My idea is use numpy 1.6.1. but I'm open to receive ideas...

Edit query used:

SELECT country, activity, sum(metric), quarter, year 
From *table* where country IN (*countries-parameters*)... 
group by 1,2,4,5   
order by 1,4 ASC

1 Solution from bigquery query:

Select
  quarter,
  SUM(IF(country=*country*,metric,0)) AS *country*,
  ...
From *table*
Where quarter IN (1,2,3,4) and country in (*countries-parameters*)
group by 1
order by 1 ASC;
Nicolas Bortolotti
  • 555
  • 1
  • 8
  • 22

0 Answers0