The following code splits a column into two for example if I have the following string "hi.this.is.an.example" i will get separate columns for "hi" and "this".
This splits the string going from the left to right however, I want to go from right to left instead so would want "example" and "an"
df['variable'].str.split('.', 2, expand=True)
>Solution :
Like in pure python, use rsplit:
df = pd.DataFrame({'variable': ["hi.this.is.an.example"]})
df['variable'].str.rsplit('.', 2, expand=True)
output:
0 1 2
0 hi.this.is an example