【发布时间】:2021-12-29 01:48:34
【问题描述】:
我正在尝试从 pandas 专栏中获取一些内容。熊猫数据框是 df 并且有一个名为实体的列。此栏似乎包含字典。其中之一是“hashtags”,其中包含另一个字典“text”。单行中可以有多个“文本”元素。想要获取文本字段的值。下面的例子可以帮助理解。 如果我能获得有关获取主题标签值的指导,将会很有帮助。
df['entities']
输出 =>
0 {'hashtags': [], 'symbols': [], 'user_mentions': [], 'urls': [{'url': '', 'expanded_url': 'https://twitter.com/i/web/status/1460865425911205891', 'display_url': 'twitter.com/i/web/status/1…', 'indices': [117, 140]}]}
1 {'hashtags': [{'text': 'carbon', 'indices': [17, 24]}, {'text': 'nature', 'indices': [48, 55]}], 'symbols': [], 'user_mentions': [], 'urls': [{'url': '', 'expanded_url': 'https://rpujolviven.blogspot.com/2012/10/infinite-growth.html', 'display_url': 'rpujolviven.blogspot.com/2012/10/infini…', 'indices': [61, 84]}, {'url': '', 'expanded_url': 'https...
2 {'hashtags': [{'text': 'Lincoln', 'indices': [69, 77]}], 'symbols': [], 'user_mentions': [], 'urls': [{'url': '', 'expanded_url': 'https://thelincolnite.co.uk/2021/11/professor-duncan-french-the-juggernaut-of-climate-politics-rolls-on/', 'display_url': 'thelincolnite.co.uk/2021/11/profes…', 'indices': [78, 101]}]}
3 {'hashtags': [{'text': 'CBDC', 'indices': [107, 112]}], 'symbols': [], 'user_mentions': [], 'urls': [{'url': , 'expanded_url': 'https://twitter.com/i/web/status/1460865388699344900', 'display_url': 'twitter.com/i/web/status/1…', 'indices': [115, 138]}]}
预期输出:
0 []
1 ['carbon', 'nature']
2 ['Lincoln']
3 ['CBDC']
【问题讨论】:
标签: python python-3.x dataframe dictionary tweepy