"Keelung" used to be written in the homophonous characters meaning "Rooster Cage" (雞籠), named after a local mountain of such a shape. Another theory suggests that the characters were transcription of a Ketagalan placename. The characters were changed in 1875 (Qing Dynasty) to mean "The Base that Prospers".
In 1863, the Qing Empire opened up Keelung as a trading port. A systematic city development started in 1895 during the Japanese Occupation. Keelung became a town in Keelung District, Taipei Prefecture in 1920 and was upgraded to a city of Taipei Prefecture in 1924. Coal mining peaked in 1968.
A new city was established in the Taipei basin for the new bureaucracy, located between two populous towns, Bangka (艋舺) and Dadaocheng (大稻埕).
This and the fact that the city is highly dependent on commerce and finance which would be disrupted in case of conflict with the People's Republic of China means that the city is more favorable to Chinese reunification than other areas of Taiwan.
Both Hanyu Pinyin, which is used both in the PRC and in TaipeiCity itself, and TongyongPinyin, which is mandated by the central government, reflect this pronunciation, romanizing Taipei as Taibei, a spelling that is closer to the Mandarin pronunciation.