我有一个像下面这样的大熊猫
tno,tdate,buyprice,sellprice,qty,t1,t2
1,2017,10,20,5,teamA,teamB
2,2017,5,10,5,teamB,teamA
预期操作:
tno,tdate,buyprice,sellprice,qty,t1,t2
1,2017,10,20,5,teamA,NaN
1,2017,10,20,5,NaN,teamB
2,2017,5,10,5,teamB,NaN
2,2017,5,10,5,NaN,TeamA
现在的情况是我将两个不同团队之间的内部事务分离为两个不同事务中的一个。你知道吗
我试着用df.unstack()
并且读了this answer我不知道如何告诉熊猫我想要解开它。你知道吗
更新1:
问题的大背景是:
tno,tdate,buyprice,sellprice,qty,Buyerteam,Sellerteam
1,2017,10,20,5,teamA,teamB
2,2017,5,10,5,teamB,teamA
有两种类型的交易
qty*(buyprice or sell price)
来计算团队的支出。如果buyTeam是NaN,则执行qty*sellprice
,if sellTeam=NaN I do qty*buyprice
。你知道吗qty*(buyprice or sellprice)
条件就不能应用我希望我介绍南的意图是明确的。你知道吗
如果可能,团队的一个输出列使用^{} :
编辑:如果只有两个团队可以将^{} 与^{} 一起使用,则相同列顺序的last使用^{} 和last ^{} :
相关问题 更多 >
编程相关推荐