【问题标题】:How to extract text from nested list in python and put in column?如何从python中的嵌套列表中提取文本并放入列中?
【发布时间】:2021-04-29 11:12:43
【问题描述】:

这是第一次观察。我需要这些都在不同的列而不是同一列。

[{'route': 'Oral',
  'brand_name': 'MSK',
  'active_ingredients': [{'dose': {'denominator_unit': 'Unknown',
     'numerator': '1',
     'numerator_unit': 'Unknown',
     'denominator': '1'},
    'name': 'Diethylcarbamazine, Oxibendazole'}],
  'atc_vet_code': 'QP52AC57',
  'dosage_form': 'Tablet',
  'manufacturer': {'registration_number': 'USA-USFDACVM-N136483',
   'name': 'MSK'}}]

我希望结果看起来像这样。

route brand name active_ingredients brand name atc_vet_code dosage_form'
oral MSK Diethylcarbamazine, Oxibendazole QP52AC57 tablet

【问题讨论】:

  • 看来结果输出不正确。 dosage_from ?

标签: python pandas list dictionary nested-lists


【解决方案1】:

您可能想在这里查看答案Convert list of dictionaries to a pandas DataFrame

相关的答案是关于json_normalize的那个。 https://stackoverflow.com/a/53831756/381179

嵌套字典列表几乎就是 json 数据格式的样子,而不是编写一些自定义的读入功能,您可以使用已经存在的内容

【讨论】:

  • 我将所有这些数据都放在一个数据框中。
猜你喜欢
  • 1970-01-01
  • 2018-03-23
  • 2020-06-01
  • 1970-01-01
  • 2015-10-15
  • 2019-03-06
  • 2022-10-12
  • 1970-01-01
  • 2022-01-05
相关资源
最近更新 更多