Relative Content

Tag Archive for pythondataframegroup-bytransform

applying a transformation function on result of group by in python

import pandas as pd data = { ‘Name’: [‘Alice’, ‘Alice’, ‘Charlie’, ‘Charlie’], ‘Age’: [25, 30, 35, 40], ‘branch’: [‘New York’, ‘Los Angeles’, ‘Chicago’, ‘Houston’] } df = pd.DataFrame(data) # concatenate the string df[‘branch’] = df.groupby([‘Name’])[‘branch’].transform(lambda x : ‘ ‘.join(x)) # show the dataframe print(df) can anyone expain what’s happening when we apply transformation function on […]