-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
struct.rename_fields
enhancements: correct name count & dict input
#10777
Comments
Too few names dropping missing columns is not intended: #9052 (comment) |
Why though? A normal rename can do partial renames, shouldn't |
It seems the balance is between there being a use case for wanting to rename the first n fields positionally vs simply accidentally feeding too few arguments to the rename. I know I'm much more likely to be in the latter camp than the former. Additionally, if you are in the former camp and get an error here, you'll know how to address it. |
Would be great to have |
@DGolubets df = rating_Series.to_frame()
df.schema["ratings"]
# Struct({'Movie': String, 'Theatre': String, 'Avg_Rating': Float64})
df.with_columns(
pl.col("ratings").name.map_fields(lambda f:
{"Movie": "Film", "Theatre": "State"}.get(f, f)
)
).schema["ratings"]
# Struct({'Film': String, 'State': String, 'Avg_Rating': Float64}) |
@cmdlineluser Great! |
+1 on |
Problem description
Adjusting struct field names currently is a little weird with
rename_fields
Length of
names
parameterTo discuss:
Comparison to Dataframe columns:
df.columns = [...]
ShapeError: X column names provided for a dataframe of width Y
Add option to provide a mapping to adjust only selected names
Example:
rename_fields({'Movie': 'Film', Theatre': 'State'})
The text was updated successfully, but these errors were encountered: