Searching a Python Dictionary with multiple values


Searching a Python Dictionary with multiple values



I have data in the following csv file, available here:



http://s000.tinyupload.com/index.php?file_id=87473936848618674050



Screenshot of the CSV:



enter image description here



I've written the following code to import the CSV file into Python as a Pandas Dataframe, and then the code after that creates a Dict. The dictionary has to have name and region as the keys, and the Windows and Linux prices as the dictionary values.




#Import libraries and CSV file into dataframe, renaming columns, printing head

import pandas as pd

df = pd.read_csv('file.csv')

col_names = ['Name','Region','API', 'Memory','vCPU', 'Storage', 'Linux', 'Windows' ]

df.columns = col_names

#Creating Dict
dict = {}

for i in df.index:

key = (df.at[i, 'Name'] , df.at[i, 'Region']) #Rename columns accordingly
value = (df.at[i, 'vCPU'], df.at[i, 'Memory'], df.at[i, 'Storage'], df.at[i, 'Windows'] , df.at[i, 'Linux'])

dictionary = {key:value}
dict.update(dictionary)



I now would like to write a function that would allow me to search through the dictionary.



For example, the user would input "32" for vCPUs, the function would bring back the region, name, and Linux and Windows prices for any processors that have 32 vCPUs.



Later, I want to implement this search function for vCPU, Memory and Storage. (the full CSV has 1700 rows). Would really appreciate someone helping me out.









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

List of Kim Possible characters

Audio Livestreaming with Python & Flask

NSwag: Generate C# Client from multiple Versions of an API