小编Arp*_*pit的帖子

Pandas:计算两列的不同组合并添加到Same Dataframe

需要帮助将两列的唯一组合添加到pandas中的同一数据框中.我想要那个"nos"专栏.

Input:
id  acct_nos name
1   1a       one
1   1a       two
2   2b       three
3   3a       four
3   3b       five
3   3c       six
3   3d       seven
Run Code Online (Sandbox Code Playgroud)

这是我想要的输出:

Output:
id  acct_nos    nos name
1   1a          1   one 
1   1a          1   two
2   2b          1   three
3   3a          4   four
3   3b          4   five
3   3c          4   six
3   3d          4   seven
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,Id = 1只有1个acct_nos-1a,因此nos必须具有值1.Id = 3只有4个acct_nos-3a到3d,因此nos必须具有值4.

不知道如何把它放在Python Pandas中.我能搞清楚的SQL查询.

谢谢

python size count aggregation pandas

4
推荐指数
2
解决办法
2395
查看次数

标签 统计

aggregation ×1

count ×1

pandas ×1

python ×1

size ×1