2

I have a df like below :-

import pandas as pd 
  
# intialise data of lists. 
data = {'cust':['fnwp', 'utp'], 'events':[['abhi','ashu'],'abhi']} 
  
# Create DataFrame 
df = pd.DataFrame(data) 
  
# Print the output. 
df

enter image description here

My expected outcome is :-

enter image description here

1 Answer 1

2

You can use pandas.explode() function:

>>> df.explode('events').reset_index(drop=True)

   cust events
0  fnwp   abhi
1  fnwp   ashu
2   utp   abhi
Sign up to request clarification or add additional context in comments.

3 Comments

The solution works on the df i have provided but its not working on my df which I am having. Do you have any clue why?
What is the result-error when you try it to your df?
nevermind I got it working actually i did some string operation and that's why it was not working! Thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.