根据列名称将数据帧分为两个数据帧,并根据列值对两个数据帧进行排序

时间:2019-05-21 18:58:16

标签: python python-3.x pandas pandas-groupby

我想将数据帧分为两个数据帧,并且我有一个名为“ product_type”的列名。取决于产品类型,我需要拆分主数据框并根据另一个列名“ id”对其进行排序。 ID应该匹配。

My data frame:

product, id, product_type
car1, FY-2, forecast
car1, FY-3, forecast
car1, FY-1, forecast
car3, FY-3, reference
car2, FY-1, reference
car4, FY-2, reference

Expected Result:

df1:

product, id, product_type
car1, FY-2, forecast
car1, FY-3, forecast
car1, FY-1, forecast


df2:

product, id, product_type
car3, FY-2, reference
car2, FY-3, reference
car4, FY-1, reference

two data frames are sorted based on the id split based on the product_type.

0 个答案:

没有答案