Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pd df explode

df.explode('A')
Comment

pd.explode

stacked = df.stack().explode().reset_index()
stacked["uid"] = stacked.groupby(["level_0", "level_1"]).cumcount()
output = stacked.pivot(["level_0", "uid"], "level_1", 0).reset_index(drop=True).rename_axis(None, axis=1)

>>> output

        TGR1 TGR2 TGR3
0          1    5    4
1          7    8    1
2          5    1    8
3          9    1    3
4          1    7    2
..       ...  ...  ...
69         4    8    2
70         5    4    2
71         5    1    4
72         2    6    1
73         1    8    7

[74 rows x 3 columns]
Comment

pandas explode

	Product			Cost	Tags
0	RAM	    		100		Add-on,Electronics
1	Laptop			5000	Units,Electronics
2	Rubber Ducky	50		Units,Decoration
# above into below
	Tags		Cost
	Add-on		100
	Electronics	5100
	Units		5050
	Decoration	50
# code -->
df['Tags'] = df['Tags'].str.split(',')
df = df.explode('Tags') 
data.groupby('Tags').sum()
Comment

PREVIOUS NEXT
Code Example
Python :: python len 
Python :: how to convert lower case to upper case in python 
Python :: join tables pandas 
Python :: How to perform heap sort, in Python? 
Python :: installing python 3 to linux 
Python :: list inside a list in python 
Python :: list all pip packages 
Python :: python coin flip 
Python :: python key 
Python :: python get all numbers between two numbers 
Python :: np minimum of array 
Python :: Count upper case characters in a string 
Python :: upload image to s3 python 
Python :: python rounding 
Python :: python wait 
Python :: new line 
Python :: RSA with python 
Python :: dictionaries in python 
Python :: circular import error 
Python :: circular linked list in python 
Python :: javascript or python 
Python :: gui with pygame 
Python :: fluffy ancake recipe 
Python :: get ip python 
Python :: timeit command line 
Python :: flask_jinja structure 
Python :: flask set mime type 
Python :: how to print multiple integers in python in different line 
Python :: hur många partier sitter i riksdagen 
Python :: function TBone() if 2=2 then print("Sup") end 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =