data<-data[c(8,1:7)]
Basically, move the last column to the first position. How would I do this in Python by using only column indices, preferably in a single line?
use numpy.r_
This was intended to allow R
like syntax for array slicing. Hence the r_
Assuming your dataframe is named df
import numpy as np
import pandas as pd
df = df.iloc[:, np.r_[8, 1:7]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With