Skip to content
Advertisement

How to split a column in two columns

I have an issue with a table called “movies”. I found the date and the movie title are both in the title column. As shown in the picture:

Sample

I don’t know how to deal with this kind of issues. So, I tried to play with this code to make it similar to MySQL codes but I didn’t work anyways.

DataFrame(row.str.split(' ',-1).tolist(),columns = ['title','date'])

How do I split it in two columns (title, date)?

Advertisement

Answer

After struggling and searching I was able to build this command which works perfectly.

select
   translate(substr(title,0,length(title) -6) ,'', '') as title,
   translate(substr(title, -5) ,')', '') as date
from movies;

Thanks for the people who answered too!

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement