Creating columns that extract features from the value of another column in the same dataframe and calculate the mean of the extracted ‘value’ column

  numpy, pandas, python
df = {'category': ['retail', 'retail', 'airtime', 'electronic', 'retail', 'electronic', 
'retail', 'retail','airtime'],
'default': [0, 1, 1, 1,0,1,1,1,0],
'year': [2011, 2013, 2014, 2015,2016,2017,2018,2010,2009],
'value': [6000, 6500, 3000, 1200,3200,4530,2100,1000,3400]}
df = pd.DataFrame(df2)
df
df[['category'=='retail', 'default'==1, 'value']].value.counts()
df[['category'=='retail', 'default'==1, 'value']].mean()

My expected output should look like the image below and the mean of the extracted value column

enter image description here

Source: Python Questions

LEAVE A COMMENT