KnowledgeBoat Logo
|

Informatics Practices

Complete the given Python code to get the required output as: Rajasthan

import ............... as pd
di = { 'Corbett' : 'Uttarakhand', 'Sariska ' : 'Rajasthan', 'Kanha' : 
'Madhya Pradesh', 'Gir' : 'Gujarat ' }
NP = ............... . Series( ............... )
print(NP[ ............... ])

Python Pandas

7 Likes

Answer

import pandas as pd
di = { 'Corbett' : 'Uttarakhand', 'Sariska' : 'Rajasthan', 'Kanha' : 
'Madhya Pradesh', 'Gir' : 'Gujarat' }
NP = pd. Series(di)
print(NP['Sariska'])
Output
Rajasthan
Explanation
  1. import pandas as pd : This line imports the pandas library and assign it the alias pd.
  2. NP = pd.Series(di) : This line creates a pandas Series object NP from the dictionary di.
  3. print(NP['Sariska']) : This line accesses the value associated with the key 'Sariska' in the Series object NP and print it. Since the value is 'Rajasthan', it gets printed.

Answered By

2 Likes


Related Questions