简体   繁体   中英

Shift column names to the left by 1 column

What it looks like: https://imgur.com/a/5ls8XXD .

What I need it to look like: https://imgur.com/a/L2uhoXY

I imported the file as a tsv and converted it into a csv. After doing so, this is how I imported my data train = pd.read_csv('./gene_train.csv', sep ='\\t') train.shape

You did not show how your dataframe looks like. But in general, you can get a list of all column names of a dataframe by

colnames = list(train.columns)

and now you said it is shifted by +1 to the right. I assume it means data of column 1 should match colnames[2] . So you can re-assign the column name by:

train.columns = colnames[1:]

but, in this way, you will miss the "rightmost" or last column and you have to fix that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM