我需要添加一个基于外部表vprices的新列“price”。在
我试着像示例中那样添加它,但是遇到了一个错误,因为括号中的df[“vol type”]是一个序列变量,而不是serie的第n个值,这正是我需要的。在
如何重写它以使用每行的值填充新列“real_size”?在
virtsizes = {
"type1": { "gb": 1.2, "xxx": 0, "yyy": 30 },
"type2": { "gb": 1.5, "xxx": 2, "yyy": 20 },
"type3": { "gb": 2.3, "xxx": 0.1, "yyy": 10 },
}
df = pd.read_csv(StringIO(src),names=["vol-id","size","vol-type"])
df["real_size"] = df["size"] * ( virtsizes[df["vol-type"]]["gb"]
谢谢!在
按} :
loc
选择的df1
行使用^{另一种解决方案是在
^{pr2}$dict comprehension
中提取gb
:虽不如耶斯列一世圣洁,但这也行得通:
相关问题 更多 >
编程相关推荐