Masiur1995
Masiur1995

Reputation: 15

Shift column names to the left by 1 column

What it looks like: https://i.sstatic.net/Kefkf.jpg.

What I need it to look like: https://i.sstatic.net/yEa9Y.jpg

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

Upvotes: 0

Views: 1307

Answers (1)

adrtam
adrtam

Reputation: 7211

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.

Upvotes: 1

Related Questions