judahrand opened a new issue, #40644:
URL: https://github.com/apache/arrow/issues/40644
### Describe the enhancement requested
Pandas allows a mapping to be passed like `df.rename(columns={'foo':
'bar'})`. This is often very useful when you only want to rename a subset of
the columns. Currently, `rename_columns` only accepts a list of all column
names.
I propose that `rename_columns` be extended to accept a `Mapping[str, str]`.
All columns with a name matching a key of the mapping will be renamed to the
relevant value. If any key does not correspond to at least one column then a
`KeyError` should be raised.
Example:
```python
>>> import pyarrow as pa
>>> import pandas as pd
>>> df = pd.DataFrame({'n_legs': [2, 4, 5, 100],
... 'animals': ["Flamingo", "Horse", "Brittle stars",
"Centipede"]})
>>> batch = pa.RecordBatch.from_pandas(df)
>>> new_names = {"n_legs": "n", "animals": "name"}
>>> batch.rename_columns(new_names)
pyarrow.RecordBatch
n: int64
name: string
----
n: [2,4,5,100]
name: ["Flamingo","Horse","Brittle stars","Centipede"]
```
### Component(s)
Python
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]