Mexico City, where it lies

In Mexico City, the huge federal capital of Mexico, the climate is subtropical, mild or pleasantly warm during the day, with cool nights in summer and cold nights in winter. In fact, the daily temperature range is remarkable, especially in the dry season.
The city is located at a tropical latitude, but at a high altitude, ranging between 2,200 and 2,600 metres (7,200 and 8,500 ft), in the so-called tierras frìas.
Here are the average temperatures.
Mexico City - Average temperatures
Min (°C)6791112121212121087
Max (°C)212326272725232322222221
Min (°F)434548525454545454504645
Max (°F)707379818177737372727270

Rainfall is concentrated in the summer months: it exceeds 100 millimetres (4 inches) per month from June to September, and it's moderate in May and October, while it's scarce in the other months. Typically, the rains occur in the form of showers in the afternoon or evening, and when they are abundant they can make it difficult to get around. The dry season is long, since it goes from November to April. The total rainfall is around 550/650 mm (21/25 in) per year in the eastern districts, while it increases in the western districts, up to 1,000 mm (40 in) per year in the Bosques de las Lomas, which are located at the foot of mountains, which are more than 3,000 metres (9,800 ft) high and are able to enhance the summer rains.
Here is the average precipitation.
Mexico City - Average precipitation

In winter, from November to February, it's cold at night, while daytime temperatures are pleasant. In the city, the "urban heat island effect" reduces the overnight cooling, but in the countryside and in the less urbanized neighbourhoods the temperature can get to the freezing point (0 °C or 32 °F). Already in February the daytime temperature begins to rise, often exceeding 25 °C (77 °F). It hardly ever rains. Sometimes there can be windy days, which have the advantage of cleaning the air.

Spring is the warmest season, at least during the day, thanks to the higher amount of sunshine. In April and May the temperature often touches 30 °C (86 °F); at night, however, it can still be a bit cold. In May, the first rains begin.

Summer, from June to September, is the wettest season: rain showers occur almost daily, although they are rarely abundant. The weather is mild, and the temperature range is reduced compared with the previous months: daytime temperatures are virtually the same as in winter, while at night they are cool but not cold.

Autumn is short: in October, a month still quite mild, the last rains occur, while in November actually it's already winter, and nights become cold again.

Mexico City

The amount of sunshine is never very good, because the weather can remain variable or cloudy even during the dry winter period, however, it is acceptable in winter and spring, before the summer rains, while cloudiness is frequent and widespread in summer. The pall of pollution that hangs over the city makes the sky often veiled and the air hazy. Anyway, the tropical sun is very strong, also because the city is located at high altitudes, especially when it is highest above the horizon around noon, ie from April to August.
Mexico City - Sunshine

When to go

The best time to visit Mexico City runs from November to April, being the dry season. Within this period, we can make some distinctions: in winter, from November to February, and sometimes in March, cold nights are more frequent, with lows around freezing; from February to April it's the sunniest period, and daytime temperatures are a bit higher, especially in March and April. All in all the best months are March and April. Due to the remarkable temperature range between night and day, in the dry season it's better to dress in layers, with warm clothes for the evening, and light for the day. Sunscreen, hat and sunglasses can be useful as well.
The months of May and October can be considered as an option as well: the rains are quite frequent, but less than at the height of the rainy season, and there is the advantage that nights are less cold than in winter.