while reading through the Pandas shift method, i was just doing some test to see if a Column in Pandas dataFrame having mixed vales like number and names and i want to segregate that in order to get the number to be aligned to a separate new column while dropping /removing them From original column.
a) Below is mine DataFrame:
>>> df
Name OXA
0 SAN 109 Yes
1 KENI 122 No
2 REEMA 455 Yes
b) I tried with shift to move number to a new DataFrame(Nums
):
>>> df['Nums'] = df['Name'].shift(-1)
>>> df
Name OXA Nums
0 SAN 109 Yes KENI 122
1 KENI 122 No REEMA 455
2 REEMA 455 Yes NaN
The above Creates the New column as Nums
but not getting the desired result.
c) My Desired output will be :
Name OXA Nums
0 SAN Yes 109
1 KENI No 122
2 REEMA Yes 455
OR and vice versa
Name OXA NUMS
0 109 Yes SAN
1 122 No KENI
2 455 Yes REEMA