【问题标题】:How can I split out this list containing a dictionary into separate columns?如何将此包含字典的列表拆分为单独的列?
【发布时间】:2021-02-03 23:06:41
【问题描述】:

上表是我拥有的,下表是我想要的。我在 Pandas 数据框中执行此操作。任何帮助将不胜感激。

谢谢!

【问题讨论】:

  • 您的sentiment 列是列表还是表示列表的字符串?

标签: python pandas list dataframe dictionary


【解决方案1】:

如果您为此提供代码 sn-p 会很好,因为我们无法轻松测试您的案例。

以下几行应该可以完成这项工作:

df['label'] = df['sentiment'].apply(lambda x: x[0]['label'])
df['score'] = df['sentiment'].apply(lambda x: x[0]['score'])

【讨论】:

  • 抱歉,我试图在 Mark down 中提供表格,但堆栈溢出不喜欢这种格式。我认为这可能与列表中的字典有关!
猜你喜欢
  • 2020-02-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-21
  • 2021-07-17
  • 2021-10-04
  • 2022-11-23
  • 1970-01-01
相关资源
最近更新 更多