waves question and its datapoints in Crosstab columns to see the shift in trends over time.
For that, you can set appropriate audiences (we’ll call them fb_boomers and fb_millennials) as rows and the waves
of the last 4 quarters as columns:
Documentation Index
Fetch the complete documentation index at: /docs/llms.txt
Use this file to discover all available pages before exploring further.
{
"base_audience": {
"id": "1",
"name": "All Internet Users",
"expression": null
},
"locations": [
"s2_1"
],
"waves": [
"q1_2024",
"q2_2024",
"q3_2024",
"q4_2024"
],
"rows": [
{
"id": "1",
"name": "fb_boomers",
"expression": {
"and": [
{
"question": "q42011a",
"datapoints": [
"q42011a_3"
],
"suffixes": [
1,
2
]
},
{
"question": "q3new",
"datapoints": [
"q3new_1"
]
}
]
}
},
{
"id": "2",
"name": "fb_millennials",
"expression": {
"and": [
{
"question": "q42011a",
"datapoints": [
"q42011a_3"
],
"suffixes": [
1,
2
]
},
{
"question": "q3new",
"datapoints": [
"q3new_3"
]
}
]
}
}
],
"columns": [
{
"id": "1",
"name": "Q1 2024",
"expression": {
"question": "waves",
"datapoints": [
"q1_2024"
]
}
},
{
"id": "2",
"name": "Q2 2024",
"expression": {
"question": "waves",
"datapoints": [
"q2_2024"
]
}
},
{
"id": "3",
"name": "Q3 2024",
"expression": {
"question": "waves",
"datapoints": [
"q3_2024"
]
}
},
{
"id": "4",
"name": "Q4 2024",
"expression": {
"question": "waves",
"datapoints": [
"q4_2024"
]
}
}
]
}
import requests
import json
import pandas as pd
with open('req.json', 'r') as file:
request_json = json.load(file)
url = 'https://api.globalwebindex.com/v2/query/crosstab'
headers = {"Authorization": "Bearer YOUR_API_KEY"}
response = requests.post(url, json=request_json, headers=headers)
response.raise_for_status()
# Process the response (JSON Lines format)
results = []
for line in response.iter_lines():
if line:
obj = json.loads(line)
if obj.get('row_index') and obj.get('column_index'): # Check for non-zero index values
row_name = obj['row']['name']
column_name = obj['column']['name']
percentage = obj['intersect']['percentage']
results.append((row_name, column_name, percentage))
# Convert the results to a DataFrame and pivot the table for readability
df = pd.DataFrame(results, columns=['Row Name', 'Column Name', 'Percentage'])
pivot_table = df.pivot(index='Row Name', columns='Column Name', values='Percentage').reset_index()
print(pivot_table.to_string(index=False))
{
"row": {
"id": "1",
"name": "fb_boomers",
"expression": {
"and": [
{
"question": "q42011a",
"options": [
"q42011a_3"
],
"suffixes": [
1,
2
]
},
{
"question": "q3new",
"options": [
"q3new_1"
]
}
]
}
},
"row_index": 1,
"column": {
"id": "1",
"name": "Q1 2024",
"expression": {
"question": "waves",
"options": [
"q1_2024"
]
}
},
"column_index": 1,
"audiences": {
"column": {
"audience": "1",
"size": 257758496,
"sample": 24922,
"percentage": 100,
"intersect_percentage": 100
},
"row": {
"audience": "1",
"size": 36643034,
"sample": 3728,
"percentage": 14.2,
"intersect_percentage": 14.2
}
},
"base": {
"size": 257758496,
"sample": 24922
},
"intersect": {
"size": 36643034,
"sample": 3728,
"percentage": 14.2,
"index": 100
}
}
{}
{}
...
Row Name Q1 2024 Q2 2024 Q3 2024 Q4 2024
fb_boomers 14.2 14.8 15.0 15.5
fb_millenials 16.5 15.9 15.5 15.1
waves question and its datapoints in Crosstab columns to see the shift in trends over time.
For that, you can set appropriate audiences (we’ll call them fb_boomers and fb_millennials) as rows and the waves
of the last 4 quarters as columns:
curl -X POST "https://api.globalwebindex.com/v2/saved/crosstabs" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d @req.json
{
"base_audience": {
"id": "1",
"name": "All Internet Users",
"expression": null
},
"locations": [
"s2_1"
],
"waves": [
"q1_2024",
"q2_2024",
"q3_2024",
"q4_2024"
],
"rows": [
{
"id": "1",
"name": "fb_boomers",
"expression": {
"and": [
{
"question": "q42011a",
"datapoints": [
"q42011a_3"
],
"suffixes": [
1,
2
]
},
{
"question": "q3new",
"datapoints": [
"q3new_1"
]
}
]
}
},
{
"id": "2",
"name": "fb_millennials",
"expression": {
"and": [
{
"question": "q42011a",
"datapoints": [
"q42011a_3"
],
"suffixes": [
1,
2
]
},
{
"question": "q3new",
"datapoints": [
"q3new_3"
]
}
]
}
}
],
"columns": [
{
"id": "1",
"name": "Q1 2024",
"expression": {
"question": "waves",
"datapoints": [
"q1_2024"
]
}
},
{
"id": "2",
"name": "Q2 2024",
"expression": {
"question": "waves",
"datapoints": [
"q2_2024"
]
}
},
{
"id": "3",
"name": "Q3 2024",
"expression": {
"question": "waves",
"datapoints": [
"q3_2024"
]
}
},
{
"id": "4",
"name": "Q4 2024",
"expression": {
"question": "waves",
"datapoints": [
"q4_2024"
]
}
}
]
}
import requests
import json
import pandas as pd
with open('req.json', 'r') as file:
request_json = json.load(file)
url = 'https://api.globalwebindex.com/v2/query/crosstab'
headers = {"Authorization": "Bearer YOUR_API_KEY"}
response = requests.post(url, json=request_json, headers=headers)
response.raise_for_status()
# Process the response (JSON Lines format)
results = []
for line in response.iter_lines():
if line:
obj = json.loads(line)
if obj.get('row_index') and obj.get('column_index'): # Check for non-zero index values
row_name = obj['row']['name']
column_name = obj['column']['name']
percentage = obj['intersect']['percentage']
results.append((row_name, column_name, percentage))
# Convert the results to a DataFrame and pivot the table for readability
df = pd.DataFrame(results, columns=['Row Name', 'Column Name', 'Percentage'])
pivot_table = df.pivot(index='Row Name', columns='Column Name', values='Percentage').reset_index()
print(pivot_table.to_string(index=False))
{
"row": {
"id": "1",
"name": "fb_boomers",
"expression": {
"and": [
{
"question": "q42011a",
"options": [
"q42011a_3"
],
"suffixes": [
1,
2
]
},
{
"question": "q3new",
"options": [
"q3new_1"
]
}
]
}
},
"row_index": 1,
"column": {
"id": "1",
"name": "Q1 2024",
"expression": {
"question": "waves",
"options": [
"q1_2024"
]
}
},
"column_index": 1,
"audiences": {
"column": {
"audience": "1",
"size": 257758496,
"sample": 24922,
"percentage": 100,
"intersect_percentage": 100
},
"row": {
"audience": "1",
"size": 36643034,
"sample": 3728,
"percentage": 14.2,
"intersect_percentage": 14.2
}
},
"base": {
"size": 257758496,
"sample": 24922
},
"intersect": {
"size": 36643034,
"sample": 3728,
"percentage": 14.2,
"index": 100
}
}
{}
{}
...
Row Name Q1 2024 Q2 2024 Q3 2024 Q4 2024
fb_boomers 14.2 14.8 15.0 15.5
fb_millenials 16.5 15.9 15.5 15.1
Was this page helpful?
