简体   繁体   English

如何从 python 的嵌套列表中提取文本并放入列中?

[英]How to extract text from nested list in python and put in column?

This is the first observation.这是第一个观察。 I need these all in different columns instead of the same column.我需要这些都在不同的列而不是同一列。

[{'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'}}]

I want the result to look something like this.我希望结果看起来像这样。

route路线 brand name品牌 active_ingredients有效成分 brand name品牌 atc_vet_code atc_vet_code dosage_form'剂量形式'
oral口服 MSK斯隆 Diethylcarbamazine, Oxibendazole二乙基卡巴嗪、奥苯达唑 QP52AC57 QP52AC57 tablet药片

You might want to check out the answer here Convert list of dictionaries to a pandas DataFrame您可能想在此处查看答案将字典列表转换为 pandas DataFrame

The relevant answer is the one talking about json_normalize .相关的答案是关于json_normalize的答案。 https://stackoverflow.com/a/53831756/381179 https://stackoverflow.com/a/53831756/381179

A list of nested dicts is pretty much what the json data format would look like, and rather than writing some custom read-in functionality, you can use what's already there嵌套字典列表几乎就是 json 数据格式的样子,而不是编写一些自定义读入功能,您可以使用已经存在的内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM