'Is there any way to shift row values in the dataframe?

I want to shift values of row 10 , Fintech into next column and fill the city column in same row with Bahamas. Is there any way to do that? enter image description here

I found the dataframe.shift() function of pandas but it is limited to columns and it shifts all the values.



Solution 1:[1]

Use DataFrame.shift with filtered rows and axis=1:

#test None values like Nonetype
m = df['Select Investors'].isna()
#test None values like strings
#m = df['Select Investors'].eq('None')

df.loc[m, 'Country':] = df.loc[m, 'Country':].shift(axis=1)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jezrael