What pandas function is most similar to the transpose procedure in SAS?
I am trying to transpose Amt
by Txn_ID
across Item_Desc
in Python using pandas. Which pandas function(s) is/are most similar to the transpose procedure in SAS?
Below is an example of the input dataframe and the desired output dataframe.
Input DataFrame:
| Txn_ID | Item_Desc | Amt |
|--------|-----------|------|
| 1 | Apples | 0.96 |
| 1 | Milk | 2.10 |
| 2 | Eggs | 7.00 |
| 2 | Flour | 2.20 |
| 2 | Salt | 4.75 |
| 3 | Eggs | 3.50 |
Output DataFrame:
| Txn_ID | Apples | Eggs | Flour | Milk | Salt |
|--------|--------|------|-------|------|------|
| 1 | 0.96 | NaN | NaN | 2.10 | NaN |
| 2 | NaN | 7.00 | 2.20 | NaN | 4.75 |
| 3 | NaN | 3.50 | NaN | NaN | NaN |
Topic sas pandas statistics data-cleaning
Category Data Science