我需要以下帮助:
我有一个以下CSV文件,已加载到数据框“ df”中。存在多个区域,每个“名称”对应的“内存”,“ vCPU”和“存储”的值不同。此数据框中有1700行。
我需要创建一个包含以下内容的字典:
键是一个具有两个元素的元组:名称和区域
字典的值是一个元组:Windows按需成本和Linux按需成本
最终,我想创建一个执行以下操作的程序: 用户输入某个CPU,Ram和Storage,程序将对数据进行排序并提取名称,以及如果存在匹配项,则显示该处理器的Windows和Linux价格,否则将拉近该处理器。输入的值。谢谢!
Name Region API Memory vCPUs Storage Linux Windows
0 M1 General Purpose Small US West - NorCal m1.small 1.7 GiB 1 vCPUs 160 GiB $0.047000 hourly $0.078000 hourly
1 M1 General Purpose Medium US West - NorCal m1.medium 3.75 GiB 1 vCPUs 410 GiB $0.095000 hourly $0.157000 hourly
2 M1 General Purpose Large US West - NorCal m1.large 7.5 GiB 2 vCPUs 840 GiB $0.190000 hourly $0.314000 hourly
3 M1 General Purpose Extra Large US West - NorCal m1.xlarge 15.0 GiB 4 vCPUs 1680 GiB $0.379000 hourly $0.627000 hourly
4 C1 High-CPU Medium US West - NorCal c1.medium 1.7 GiB 2 vCPUs 350 GiB $0.148000 hourly $0.228000 hourly
答案 0 :(得分:1)
这是创建字典的部分
tempDict = {}
for i in df.index:
key = (df.at[i, 'Name'] ,df.at[i, 'Region']) #Rename columns accordingly
value = (df.at[i, 'Windows On-demand cost'] ,df.at[i, 'Linux On demand cost']) #Rename columns accordingly
dictionary = {key: value}
tempDict.update(dictionary)
print(tempDict)
答案 1 :(得分:0)
我会尝试这样的事情:
outdict = {k: (gdf['Windows On Demand cost'].item(),
gdf['Linux On Demand cost'].item())
for k, gdf in df.groupby(['Name', 'Region'])}