I am trying to create to dataframe using series with 0,1,2,3... with corresponding values "Qatar","USA",etc. Here is the code :
import pandas as pd
import numpy as np
dict_country_fifa = pd.Series([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32],index=["Qatar","Ecuador","Senegal","Netherlands","Argentina","Saudi Arabia","Mexico","Poland","Spain","Costa Rica","Germany","Japan","Brazil","Serbia","Switzerland","Cameroon","England","Iran","USA","Wales","France","Australia","Denmark","Tunisia","Belgium","Canada","Morroco","Croatia","Portugal","Ghana","Uruguay","South Korea"])
print(dict_country_fifa[1])
So if I print(dict_country_fifa[1])
output I get is >>> 2
# which is 1,2 <--- 2 value in Dataframe from list
But my question how do I get the index value such as Qatar or Ecuador printed??
I tried following
print(dict_country_fifa.get(3))
output is >>> 4
But I am looking to get the country name returned instead? How do I get the name instead of 4 ?
CodePudding user response:
You have set the names of the countries as an index of the Series.
Therefore you need to retrieve the names from the index as displayed below.
print(dict_country_fifa.index[3])
Output:
Netherlands