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
What will be the output produced by the following code ?
Stationery = ['pencils', 'notebooks', 'scales', 'erasers'] S = pd.Series([20, 33, 52, 10], index = Stationery) S2 = pd.Series([17, 13, 31, 32], index = Stationery) print(S + S2) S = S + S2 print(S + S2)
What will be the output produced by following code, considering the Series object S given above ?
(a) print(S[1:1])
(b) print(S[0:1])
(c) print(S[0:2])
(d)
S[0:2] = 12 print(S)
(e)
print(S.index) print(S.values)
Find the error in following code fragment :
S2 = pd.Series([101, 102, 102, 104]) print(S2.index) S2.index = [0, 1, 2, 3, 4, 5] S2[5] = 220 print(S2)
Find the error in following code fragment :
S = pd.Series(2, 3, 4, 5, index = range(4))