在python中从列表遍历树进行计算?

在python中从列表遍历树进行计算?,python,pandas,list,Python,Pandas,List,我有以下清单: new_tree = {'cues': 'glucose_tol', 'directions': '<=', 'thresholds': '122.5', 'exits': 1.0, 'children': [{'cues': True}, {'cues': 'mass_index', 'directions': '<=', 'thresholds': '30.8', 'exits': 1.0, 'children

我有以下清单:

new_tree = {'cues': 'glucose_tol',
  'directions': '<=',
  'thresholds': '122.5',
  'exits': 1.0,
  'children': [{'cues': True},
   {'cues': 'mass_index',
    'directions': '<=',
    'thresholds': '30.8',
    'exits': 1.0,
    'children': [{'cues': 'pedigree',
      'directions': '<=',
      'thresholds': '0.305',
      'exits': 1.0,
      'children': [{'cues': True},
       {'cues': 'diastolic_pb',
        'directions': '<=',
        'thresholds': '77.0',
        'exits': 1,
        'children': [{'cues': True}, 
        {'cues': 'insulin',
         'directions': '<=',
         'thresholds': '480',
         'exits': '0.5',
         'children': [{'cues': True}, {'cues': False}]}]}]}]}]}

第一个是血糖、体重指数、谱系、舒张压,并被归类为真。如何从该数据点所经过的列表中获取这4个提示,并将其保存以备将来计算?任何帮助都将不胜感激。

这看起来像一个决策树

它的工作方式是,在每个步骤中,您要么处于最终决策状态(“提示”:True,要么“提示”:false),要么需要做出决策


要做出决定,您需要从数据帧中获取名为“cues”的字段,然后使用方向和阈值形成一个条件。第一个基本上是
如果我不确定你想要什么,但这可能有帮助吗?谢谢你的回复!您能试着为您提到的python递归函数编写一个伪代码吗?
print(df)

times_pregnant,glucose_tol,diastolic_pb,triceps,insulin,mass_index,pedigree,age,label
6,148,72,35,0,33.6,0.627,50,1
1,85,66,29,0,26.6,0.351,31,0