I have a Pandas Dataframe with a column that looks like this:
Car_Make
0 2017 Abarth 124 Spider ManualConvertible
1 2017 Abarth 124 Spider AutoConvertible
2 2017 Abarth 124 Spider ManualConvertible
3 2017 Abarth 124 Spider AutoConvertible
4 2017 Abarth 595 ManualHatch
5 2017 Abarth 595 AutoHatch
Three Questions:
1 How to save split data in panda in reverse order? - This solves my problem but I don't know how or why it works - can someone please explain this to me? I hate copy pasting without understanding why it works
df['Car_Make'].apply(lambda x:pd.Series(x.split()[::-1]))
2 I have tried to replicate it using a user-defined function (that I can use again) with the following, but it doesn't appear to work (any help understanding why and the correct way to turn the Lambda function into a user-defined function
def f(x):
df[x] = pd.Series(x.split()[::-1])
return df
3 Is there a better way to split this column by space in reverse?
I have tried using Regex which works, but not on all rows as you can see row 4 and 5 a slightly different to the above.
Any help would be greatly appreciated.
Thanks, Adrian