Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

split dataframe row on delimiter python

In [1]: df = pd.DataFrame({'A': [[0, 1, 2], 'foo', [], [3, 4]],
   ...:                    'B': 1,
   ...:                    'C': [['a', 'b', 'c'], np.nan, [], ['d', 'e']]})

In [2]: df
Out[2]:
           A  B          C
0  [0, 1, 2]  1  [a, b, c]
1        foo  1        NaN
2         []  1         []
3     [3, 4]  1     [d, e]

In [3]: df.explode('A')
Out[3]:
     A  B          C
0    0  1  [a, b, c]
0    1  1  [a, b, c]
0    2  1  [a, b, c]
1  foo  1        NaN
2  NaN  1         []
3    3  1     [d, e]
3    4  1     [d, e]
Comment

PREVIOUS NEXT
Code Example
Python :: pandas drop rows 
Python :: create and add many to many field in django 
Python :: pass in python 
Python :: how to make a variable in python 
Python :: problem solving with python 
Python :: string template python 
Python :: python def example 
Python :: python generators with for 
Python :: groupby as_index=false 
Python :: pack() tkinter 
Python :: image to vector conversion function 
Python :: signup 
Python :: object has no attribute python 
Python :: add user agent selenium python canary 
Python :: brownie transaction info 
Python :: python list of paths 
Python :: convert from R to python 
Python :: fcn tensorflow 
Python :: what will be the output of the following python code? i = 0 while i < 5: print(i) i += 1 if i == 3: break else: print(0) 
Python :: Spatial Reference arcpy 
Python :: pomodoro timer in python 
Python :: image segmentation pyimagesearch 
Python :: # str and int mixup in python: 
Python :: save csv with today date pandas 
Python :: Groupby geek link 
Python :: def get_context_data(self, **kwargs): 
Python :: table is not creating in django 
Python :: type operator in python 
Python :: form a chakravyuh matrix python 
Python :: spark write progress bar jupyter 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =