python - 以列格式将一个表的输出合并到另一个表

标签 python pandas list dataframe metadata

我有一个如下所示的数据框:

Plant       Date        Item          unitsSold
1          10-oct        A               15        
1          11-Oct        A               20
1          12-Oct        A               10
2          10-Oct        B               19
2          11-Oct        A               20
2          12-Oct        C               10

另一个数据集如下所示:

Plant       Date         Item        unit Price
1          10-Oct        A,B           10            ---That means both A and B have same unit price
1          11-Oct         A            14
1          12-Oct        A,B,C         10            ----That means both A, B and C have same price
2          10-oct        A,B,C         15
2          11-Oct         A            10
3          12-Oct        A,C           20

现在我希望我的输出看起来像这样:

Plant       Date         Item        unit Price      A.UnitsSold        B.Unitssold          C.unitssold
1          10-Oct        A,B           10            15                    0                     0    --Since only a was sold on 10-oct
1          11-Oct         A            14            20                    0                     0
1          12-Oct        A,B,C         10            10                    0                     0   
2          10-oct        A,B,C         15            0                     19                    0
2          11-Oct         A            10            20                    0                     0
3          12-Oct        A,C           20            0                     0                     10

谁能告诉我如何获取已售单位的列。注意-可以有任意数量的样式

最佳答案

与列合并

df_new =pd.concat([df1, df2], axis=1)

关于python - 以列格式将一个表的输出合并到另一个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58968320/

相关文章:

c# - WPF 绑定(bind) : How to bind a name from a list of filepaths to text of TextBlock in ListBox?

python - 列表的列表的元素到列表

python - 运行时错误 : There is no current event loop in thread in async + apscheduler

python - 在 JSON 序列化中嵌套一组带有新 header 的列

python - 创建新行并根据时间间隔重复这些值(如果它们属于)

python - Pandas TimeGrouper 和 Pivot?

Python:将列表的批处理元素放入预定义的组中

python - 如果在列文本字符串中找到值,如何使用字典键添加新的数据框列

python - 谷歌 Colab 未加载

python - 将列表与 Python 中的 pandas 中的日期进行比较