mercredi 4 juillet 2018

Pandas shift column data upon condition

I have dataframe which look like this.

    Name    Val Rating  
0   ABC     123 B + 
1   DEF     234 B + 
2   567     B-  NaN
3   GHI     890 D

but instead I want to shift the data by checking (col['Name']) to next column (col['Val']) and successively shifting. Also if the shifting happens change the row index value. I want the following dataframe as output.

    Name    Val Rating  
0   ABC     123 B + 
1   DEF     234 B + 
    NaN     567 B - 
2   GHI     890 D

Anybody know how to do this?

Aucun commentaire:

Enregistrer un commentaire