python - Pandas shift column data upon condition - Stack Overflow

PHOTO EMBED

Mon Apr 19 2021 09:24:54 GMT+0000 (Coordinated Universal Time)

Saved by @siddharth #python

mask = pd.to_numeric(df['Name'], errors='coerce').notnull()
df[mask] = df[mask].shift(axis=1)
print (df)
  Name  Val Rating
0  ABC  123    B +
1  DEF  234    B +
2  NaN  567     B-
3  GHI  890      D
content_copyCOPY

Masks in pandas

https://stackoverflow.com/questions/51184346/pandas-shift-column-data-upon-condition