Python Forum
shifting specific column to before/after specific column in dataframe
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
shifting specific column to before/after specific column in dataframe
#2
You can specify the order of columns as you want, e.g.:

x=pd.DataFrame({'a': [1,2,3], 'b':[3,4,5], 'c':[5,6,7]})
x = x[['b','c','a']]
Output:
b c a 0 3 5 1 1 4 6 2 2 5 7 3
Reply


Messages In This Thread
RE: shifting specific column to before/after specific column in dataframe - by scidam - Mar-19-2019, 04:42 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Schedule exit a program at a specific time 4 am every day. chubbychub 3 296 May-17-2024, 03:45 PM
Last Post: chubbychub
  Adding PD DataFrame column bsben 2 386 Mar-08-2024, 10:46 PM
Last Post: deanhystad
  Get an average of the unique values of a column with group by condition and assign it klllmmm 0 463 Feb-17-2024, 05:53 PM
Last Post: klllmmm
  delete specific row of entries jacksfrustration 3 473 Feb-13-2024, 11:13 PM
Last Post: deanhystad
  Help copying a column from a csv to another file with some extras g0nz0uk 3 536 Feb-01-2024, 03:12 PM
Last Post: DeaD_EyE
  Converting column of values into muliple columns of counts highland44 0 311 Feb-01-2024, 12:48 AM
Last Post: highland44
  Extracting specific file from an archive tester_V 4 609 Jan-29-2024, 06:41 PM
Last Post: tester_V
  Python code to set column width 1418 11 1,630 Jan-20-2024, 07:20 AM
Last Post: Pedroski55
  Why can't I copy and past only ONE specific tab? NewWorldRonin 8 993 Jan-12-2024, 06:31 PM
Last Post: deanhystad
  data validation with specific regular expression shaheen07 0 390 Jan-12-2024, 07:56 AM
Last Post: shaheen07

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020