mercredi 10 juin 2020

extracting random data from excel and convert to dict [duplicate]

data:

row1 (col1)Country (col2)Capital (col3)Continent

row2 Malaysia K.L Asia

row3 Uruguay Montevideo S.America

row4 Ethiopia Addis Ababa Africa

import pandas as pd
df = pd.read_excel("filename",usecols=[0,1])
country_bio = df.sample(n=1)
country_bio = country_bio.values

d={country:capital for country,capital in country_bio}

output d= {'Ethiopia':'Addis Ababa'}

I would like to pick a random country and capital (excluding continent) from excel and turn it into dictionary .Is there a better way to get the same result?Thanks :)




Aucun commentaire:

Enregistrer un commentaire