KnowledgeBoat Logo
|

Informatics Practices

Write a Python program to create a series object, country using a list that stores the capital of each country.

Note. Assume four countries to be used as index of the series object are India, UK, Denmark and Thailand having their capitals as New Delhi, London, Copenhagen and Bangkok respectively.

Python Pandas

5 Likes

Answer

import pandas as pd
capitals = ['New Delhi', 'London', 'Copenhagen', 'Bangkok']
countries = ['India', 'UK', 'Denmark', 'Thailand']
country = pd.Series(capitals, index=countries)
print(country)

Output

India        New Delhi
UK              London
Denmark     Copenhagen
Thailand       Bangkok
dtype: object

Answered By

2 Likes


Related Questions