Q:

Pandas map (reorder/rename) columns using JSON template

I have a data frame like so:
|customer_key|order_id|subtotal|address        |
------------------------------------------------
|12345       |O12356  |123.45  |123 Road Street|
|10986       |945764  |70.00   |634 Road Street|
|32576       |678366  |29.95   |369 Road Street|
|67896       |198266  |837.69  |785 Road Street|

And I would like to reorder/rename the columns based on the following JSON that contains the current column name and the desired column name:
{
"customer_key": "cust_id",
"order_id": "transaction_id",
"address": "shipping_address",
"subtotal": "subtotal"
}

to have the resulting Dataframe:
|cust_id|transaction_id|shipping_address|subtotal|
--------------------------------------------------
|12345  |O12356        |123 Road Street |123.45  |
|10986  |945764        |634 Road Street |70.00   |
|32576  |678366        |369 Road Street |29.95   |
|67896  |198266        |785 Road Street |837.69  |

is this something that's possible? if it makes it easier, the order of the columns isn't critical.

A:

For renaming and ordering you would need to reindex after renaming
df.rename(columns=d).reindex(columns=d.values())

or:
df.reindex(columns=d.keys()).rename(columns=d)

