ENH: moving columns to first or last index of a dataframe
See original GitHub issueFeature Type
-
Adding new functionality to pandas
-
Changing existing functionality in pandas
-
Removing existing functionality in pandas
Problem Description
I wish I can use a function to move a column in the start or end of a DataFrame using moveToStart and moveToEnd functions.
Feature Description
df.moreToStart("target")
df.moveToEne("target")
Alternative Solutions
temp_cols=df.columns.tolist()
index=df.columns.get_loc("target")
new_cols= temp_cols[0:index] + temp_cols[index+1:] + temp_cols[index:index+1]
df=df[new_cols]
Additional Context
Moving target variables in the end to make dataset more smooth for machine learning algorithms.
Issue Analytics
- State:
- Created a year ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
How to Move a Column to First Position in Pandas DataFrame?
The basic idea to move a column in a pandas dataframe is to remove the column from its current place and insert it...
Read more >Pandas - How to Change Position of a Column
Moving first to last and last to first is simple, now let's see moving the middle column to the first position of the...
Read more >Move column by name to front of table in pandas
Show activity on this post. My current code moves the column by index using df. columns. tolist() but I'd like to shift it...
Read more >Move column to front in a Pandas DataFrame - EasyTweaks.com
1. Rearrange column to first position · 2. Move Pandas column to a specific position (in this case the second) · 3. Reorder...
Read more >could not convert string to float sklearn standardscaler
Enhancement datasets. The output variable contains three different string values. All columns of the dataframe are float and the output y is also...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
-1 as well; I don’t think this is something we should be expanding the API for. Perhaps it’d be helpful to write your own utility function(s), something like:
-1 on this, since it is just too specific task to have its own function, when methods already exist for simply display:
And any of the above are fully generalisable methods