[英]Writing elements of a frozen set to a pandas dataframe
I have a frozen set whose elements are like this: 我有一个冻结的集,其元素是这样的:
{frozenset({'e', 'f'}), frozenset({'a', 'b'}), frozenset({'c', 'd'}),....}
I want to write the elements in the frozen set to a pandas dataframe like this: 我想将冻结集中的元素写入这样的pandas数据框:
col1 col2
0 a b
1 c d
2 e f
.. .. ..
What is the most efficient way to do this? 最有效的方法是什么?
You can convert your set to a list then create the dataframe. 您可以将集合转换为列表,然后创建数据框。 Let's call your set dat
in the example below: 让我们在以下示例中将您的set dat
称为:
df = pd.DataFrame(list(dat), columns=['col1', 'col2'])
Yields a separate row in the DataFrame for each set in dat
. 为dat
每个集合在DataFrame中产生一个单独的行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.