Search code examples
pythonpandasdictionaryseries

how to convert the dictionary with the list item to the pandas.Series?


data_dict = {'A': [1,3,3], 'B': [2,3,3]} 

convert to

A 1  
A 3  
A 3  
B 2  
B 3  
B 3  

I tried to loop, but it is not simple enough. Is there any more simple method?


Solution

  • data_dict = {'A': [1,3,3], 'B': [2,3,3]}
    s = pd.Series(data_dict).explode()
    print(s)
    
    A    1
    A    3
    A    3
    B    2
    B    3
    B    3
    dtype: object