You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "judahrand (via GitHub)" <gi...@apache.org> on 2024/03/18 19:09:02 UTC
[I] [Python] Allow `rename_columns` to take a mapping [arrow]
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: issues-unsubscribe@arrow.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Python] Allow `rename_columns` to take a mapping [arrow]
Posted by "AlenkaF (via GitHub)" <gi...@apache.org>.
AlenkaF commented on issue #40644:
URL: https://github.com/apache/arrow/issues/40644#issuecomment-2056518207
Issue resolved by pull request 40645
https://github.com/apache/arrow/pull/40645
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Python] Allow `rename_columns` to take a mapping [arrow]
Posted by "AlenkaF (via GitHub)" <gi...@apache.org>.
AlenkaF closed issue #40644: [Python] Allow `rename_columns` to take a mapping
URL: https://github.com/apache/arrow/issues/40644
--
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: issues-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org