A pandas DataFrame is a two-dimensional labeled table: rows hold records and columns hold fields. It provides the working form for moving from raw data to a chart, whether the data describes monthly tourist arrivals, airport traffic, sports performance, or call-to-action content. section 2.2.1 section 2.1.1
Table 2.1 Arrivals at tourist arrivals establishments since 1994
|
Date
|
IT
|
FR
|
DE
|
PT
|
ES
|
UK
|
|---|---|---|---|---|---|---|
|
1990-01-01
|
2,543,920
|
3,185,877
|
325,138
|
1723,786
|
1,776,000
|
|
|
1990-02-01
|
2,871,632
|
3,588,879
|
381,539
|
1,885,718
|
2,250,000
|
|
|
1990-03-01
|
3,774,702
|
4,272,437
|
493,957
|
2,337,847
|
2,662,000
|
|
|
…
|
…
|
…
|
…
|
…
|
…
|
…
|
|
2019-08-01
|
11,649,500
|
13,692,822
|
14,570,339
|
2,531,809
|
12,893,366
|
8,889,049
|
|
2019-09-01
|
9,888,817
|
11,684,845
|
14,373,815
|
2,263,748
|
5,858,984
|
|
|
2019-10-01
|
7,692,388
|
10,401,793
|
13,780,441
|
1,995,942
|
7,455,781
|
This table is a DataFrame-shaped dataset: each row represents a date, while country columns hold tourist-arrival values. Missing country-year values matter, because aggregating incomplete years can produce misleading results. section 2.2.1
Start by loading a file into a DataFrame and parsing date fields correctly. For the tourist-arrivals data, parsing Date as a date makes it possible to filter a time range, extract a year, group records by year, and calculate summed arrivals before charting. section 2.2.1 section 2.4.1
Load, prepare, and chart data
Load CSV data with pandas, then use the DataFrame as the input to Altair. A basic flow is: read the file; parse Date; remove rows outside the selected years; create Year; group by Year; and calculate totals. Only after those choices are explicit should the resulting table drive a visualization. section 2.2.1 section 2.4.1 section 2.1.1
Use a separate DataFrame when chart content needs its own structured data:
- Create a one-row text DataFrame for a chart annotation, then render its text with mark_text(). section 2.3.2
- Reshape airport data with melt(), remove missing values, filter Portugal, and draw a line chart from the prepared DataFrame. section 2.3.2
- Add a URL column to a sports DataFrame so selected chart categories can receive image marks. section 4.5.2
- Create columns for call-to-action text, x positions, and image paths to drive coordinated text and image charts. section 9.2.2
A DataFrame is not only imported data. It can also be constructed directly from Python dictionaries or records when the chart needs a small supporting layer, such as an annotation, a baseline, or a next-steps panel. Keeping these values in columns lets Altair encode them consistently. section 2.3.2 section 9.2.2 section 4.5.2
Before treating totals as insight, inspect completeness and define the question. In the arrivals example, incomplete years can distort aggregation; prepared values then support a chart that is enriched with contextual evidence rather than left as an unexplained display. section 2.2.1 section 2.3.2


















