Need help adding a unique combination of two columns to the same data file in pandas. I need a nos column.
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
Here is the result I want:
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
In the above example, Id = 1 has only 1 acct_nos-1a, so nos should have a value of 1. Id = 3 has only 4 acct_nos-3a to 3d, so nos should have a value of 4.
Not sure how to do this in Python pandas. SQL queries that I can figure out.
thank
source
share