new column in pandas with where logic

Solutions on MaxInterview for new column in pandas with where logic by the best coders in the world

showing results for - "new column in pandas with where logic"
Gilberto
14 Jan 2020
1virtsizes = {
2  "type1": { "gb": 1.2, "xxx": 0, "yyy": 30 },
3  "type2": { "gb": 1.5, "xxx": 2, "yyy": 20  },
4  "type3": { "gb": 2.3, "xxx": 0.1, "yyy": 10  },
5}
6d = {k:v['gb'] for k,v in virtsizes.items()}
7print (d)
8{'type2': 1.5, 'type1': 1.2, 'type3': 2.3}
9
10df = pd.DataFrame({'vol-type':['type1','type2']})
11df["real_size"] = df["vol-type"].map(d)
12print (df)
13  vol-type  real_size
140    type1        1.2
151    type2        1.5