I have a dataframe like this:
+----------+---------------+---------------+-------------+
| Old_City | New_City_Code | New_City_Name |Old_City_Code|
+----------+---------------+---------------+-------------+
| a | 101 | A | 001 |
+----------+---------------+---------------+-------------+
| b | 101 | A | 002 |
+----------+---------------+---------------+-------------+
| c | 102 | B | 003 |
+----------+---------------+---------------+-------------+
| d | 103 | C | 004 |
+----------+---------------+---------------+-------------+
| e | 103 | C | 005 |
+----------+---------------+---------------+-------------+
| f | 103 | C | 006 |
+----------+---------------+---------------+-------------+
and I want to reshape this using pandas. The reshaped table should be:
+---------------+---------------+-----------+-----------+-----------+-----------+-----------+-----------+
| New_City_Code | New_City_Name | Old_City1 | Old_City2 | Old_City3 | Old_Code1 | Old_Code2 | Old_Code3 |
+---------------+---------------+-----------+-----------+-----------+-----------+-----------+-----------+
| 101 | A | a | b | | 001 | 002 | |
+---------------+---------------+-----------+-----------+-----------+-----------+-----------+-----------+
| 102 | B | c | | | 003 | | |
+---------------+---------------+-----------+-----------+-----------+-----------+-----------+-----------+
| 103 | C | d | e | f | 004 | 005 | 006 |
+---------------+---------------+-----------+-----------+-----------+-----------+-----------+-----------+
Is there any way for this kind of conversion in pandas (or if there isn't in pandas, in R)? I tried pivot, but it didn't work (I got error ValueError: cannot label index with a null key).