【发布时间】:2023-02-14 13:50:03
【问题描述】:
我有一个包含两个相关列的数据框,需要合并到一个 dictionary 列中。
样本数据:
skuId coreAttributes.price coreAttributes.amount
0 100 price 8.84
1 102 price 12.99
2 103 price 9.99
预期输出:
skuId coreAttributes
100 {'price': 8.84}
102 {'price': 12.99}
103 {'price': 9.99}
我试过的:
planProducts_T = planProducts.filter(regex = 'coreAttributes').T
planProducts_T.columns = planProducts_T.iloc[0]
planProducts_T.iloc[1:].to_dict(orient = 'records')
我得到 UserWarning: DataFrame columns are not unique, some columns will be omitted. 和这个输出:
[{'price': 9.99}]
你能帮我解决这个问题吗?
【问题讨论】: