[英]Pandas: compare two columns values against a nested dictionary
I was reading a lot but I couldn't figure out how can I do this.我读了很多书,但我不知道该怎么做。 I have a df with two columnns: data
and fold
, and a nested dictionary called dicDataFolds
with data
as keys and fold
as key of each dictionary like this:我有一个带有两个列的 df : data
和fold
,以及一个名为dicDataFolds
的嵌套字典,其中data
作为键, fold
作为每个字典的键,如下所示:
dicDataFolds = {'data1': {1: 111936, 2: 111928, 3: 111821, 4: 111852, 5: 111882},
'data2': {1: 1566460, 2: 1566434, 3: 1566245, 4: 1566502, 5: 1566550},
'data3': {1: 292478, 2: 316757, 3: 316671, 4: 292265, 5: 316018},
...
}
I would like to access to the dictionary in order to obtain the value pointed by the 'data' and 'fold' columns values, and store it in a new column.我想访问字典以获得“数据”和“折叠”列值指向的值,并将其存储在新列中。
Any suggestions?有什么建议么?
data
and fold
values from that Series;从该系列中提取data
和fold
值;dataframe[['data','fold']]
沿数据帧的轴 1 应用 function dataframe[['data','fold']]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.