上下文
我有一个Pandas
、DataFrame
和Use Case
,其中我需要在Columns
中存储Collection
(Dictionary
(。我知道,DataFrame
可能不是为此而设计的,然而,我正在寻找一个在多个DataFrames
、Series
等之间没有Relationships
的简单解决方案。
我目前收到以下错误:
ValueError:值(3(的长度与索引(5(的长度不匹配
代码
procedures = {'A': 'Procedure A', 'B': 'Procedure B', 'C': 'Procedure C'}
# I would like to create a new Column 'Procedures' and assign the Dictionary above to it for every Row.
data['Procedures'] = procedures
问题
Pandas
是否可以实现这一点?我如何实现这一目标
按DataFrame长度的倍数重复dict列表:
data['Procedures'] = [procedures] * len(data)
要在Pandas DataFrame中保存Dictionary,请使用pd.DataFrame.from_dict(input_dict)
。
如果您认为不清楚,请参阅此链接。