Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas reverse explode

# Turn the column into delimited string
df = (df.groupby(['NETWORK','config_id'])
      .agg({'APPLICABLE_DAYS': lambda x: ",".join(x),'Case':'mean','Delivery':'mean'})
      .rename({'Case' : 'Avg_Cases','Delivery' : 'Avg_Delivery'},axis=1)
      .reset_index())
df
Out[1]: 
   NETWORK  config_id       APPLICABLE_DAYS  Avg_Cases  Avg_Delivery
0  Grocery       5399       SUN,MON,TUE,WED         25           2.5
Comment

pandas reverse explode

# Turn the column into list
df = (df.groupby(['NETWORK','config_id'])
      .agg({'APPLICABLE_DAYS': lambda x: x.tolist(),'Case':'mean','Delivery':'mean'})
      .rename({'Case' : 'Avg_Cases','Delivery' : 'Avg_Delivery'},axis=1)
      .reset_index())
df
Out[1]: 
   NETWORK  config_id       APPLICABLE_DAYS  Avg_Cases  Avg_Delivery
0  Grocery       5399  [SUN, MON, TUE, WED]         25           2.5
Comment

PREVIOUS NEXT
Code Example
Python :: py decorateur 
Python :: accessing list elements in python 
Python :: best python library to download files 
Python :: reverse bolean python 
Python :: Drop a single column by index 
Python :: How to check if variable exists in a column 
Python :: how to scale numbers between -1 and 1 python 
Python :: login() takes 1 positional argument but 2 were given 
Python :: Difference between the remove() method and discard() method of sets in python 
Python :: webcolors python 
Python :: Unable to locate package python-obexftp 
Python :: getroot xml python 
Python :: An error occurred while connecting: 10049: The requested address is not valid in its context.. scrapy splash 
Python :: check true false in python 
Python :: using django annotations to get the last record 
Python :: Get First From Table Django 
Python :: pyqt5 running string and clock stackoverfloww 
Python :: long format to short in python 
Python :: why do we need to preprocess data 
Python :: python first letter to capitalize 
Python :: Bilgisayardaki mp3 uzantili dosyalari bulma 
Python :: selenium restart browser python 
Python :: signup generic 
Python :: filter titlecase django 
Python :: matplotlib include first number in plotter 
Python :: fibonacci 10th 
Python :: gcp jupyter use python variables in magic bigquery 
Python :: np.modf 
Python :: python zpl 
Python :: fancy index python 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =