使用Julia扩展DATAFRAME中的DICS字段列表
我在数据框中有一列是字典列表:
[{"key1": value1, "key2": "value2", "key3": "value3", "key4": "value4"}, {"key1": value1, "key2": "value2", "key3": "value3", "key4": "value4"}]
是否有办法扩展此列以获取这样的内容:
key1 key2 key3 key4
value1 value2 value3 value4
value1 value2 value3 value4
注意:键_
可以是任何字符串,value _
可以是任何值。
I have a column in a dataframe that is a list of dictionaries:
[{"key1": value1, "key2": "value2", "key3": "value3", "key4": "value4"}, {"key1": value1, "key2": "value2", "key3": "value3", "key4": "value4"}]
Is there a way to expand this column to get something like this:
key1 key2 key3 key4
value1 value2 value3 value4
value1 value2 value3 value4
Note: key_
can be any string, value_
can be any value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这很容易:
唯一的限制是,由于
dict
不能保证关键顺序,因此所产生的列的顺序未定义。您需要在第二步中重新订购它们,例如:另一种方法是:
从概念上讲,它有点复杂,需要您知道要提取的键,但是好处是您在操作中进行操作一枪。
This is quite easy:
The only limitation is that the order of resulting columns is undefined as
Dict
does not guarantee key order. You would need to re-order them in the second step e.g. like this:Another approach would be:
it is a bit more complex conceptually and requires you to know what keys you want to extract, but the benefit is that you do the operation in one shot.