Extract seperated value from columns I am working on this CSV file which is a collection of movie details from IMDB. 
In this I have a genres column in the dataframe with all the genres of the movies seperated by a pipe (|)
What I need is to extract the first two genres from the genres column and store them in two new columns: genre_1 and genre_2.
And for the columns where there is only 1 genre, extract the single genre into both the columns, i.e. for such movies the genre_2 will be the same as genre_1.

I am sharing the screen shots of the code and results that I have got. 


Now, I can create a new data frame with the genres created and can then remove the unwanted columns and can concatenate the remaining the with original data frame. But that looks pretty clumsy.
How can I crate split the column in my original data frame only and remove the unwanted expanded columns.
Any help is appreciated.
Try:
# Create an example dataframe
df = pd.DataFrame({&quot;genres&quot;:[&quot;Fantasy|Sci-Fi&quot;,
                &quot;Action|Adventure|Fantasy&quot;,
                &quot;Thriller&quot;,
                &quot;Action|Adventure|Thriller|bbv&quot;,&quot;Action&quot;,&quot;Action|Adventure|thriller&quot;]})

# Get a dataframe with as many columns as there are genres
df = df.genres.str.get_dummies(sep = &quot;|&quot;)

# Get the genres as values
df = df.multiply(df.columns)

# Rename the columns to have the genre id
df.columns = [&quot;genre_&quot; + str(x) for x in range(len(df.columns))]

Input:

Output:

EDIT:
you can simply use pandas assign method:
df.assign(genre1= df.genres.str.split(&quot;|&quot;, expand = True).iloc[:,:1],
          genre2 = df.genres.str.split(&quot;|&quot;, expand = True).iloc[:,1:2])

*Output: