Skip to content
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

Change all columns one time #17872

Closed
xiasijian opened this issue Jul 25, 2024 · 5 comments
Closed

Change all columns one time #17872

xiasijian opened this issue Jul 25, 2024 · 5 comments
Labels
documentation Improvements or additions to documentation

Comments

@xiasijian
Copy link

Description

def change_all_columns_at_once(new_col_list,psl_df):
    columns_dict = {col: None for col in psl_df.columns}
    updated_columns_dict = {key: psl_header[i] for i, key in enumerate(columns_dict)}
    return(psl_df.rename(updated_columns_dict))

Link

No response

@xiasijian xiasijian added the documentation Improvements or additions to documentation label Jul 25, 2024
@ritchie46
Copy link
Member

Sorry, is there a question?

@mcrumiller
Copy link
Contributor

Looks like the wrong place to post this. But FYI here is a more concise version:

df = df.rename({x:y for x,y in zip(df.columns, new_col_list)})

@markxwang
Copy link
Contributor

markxwang commented Jul 28, 2024

Looks like the wrong place to post this. But FYI here is a more concise version:

df = df.rename({x:y for x,y in zip(df.columns, new_col_list)})

Well..you can just dict(zip(l1, l2))

@xiasijian
Copy link
Author

question

I am sorry, I just mark the example for this usage. Not question. Thanks

@ritchie46
Copy link
Member

I am closing this as this is not a forum for examples. Maybe consider StackOverflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

4 participants