What error do you get with?
ave = data.groupby('Segment').median()
I think that should work, maybe there's something in your data causing the error, like nan's, im just guessing. You could try applying your own median function to see if you can work around the cause of the error, something like:
def mymed(group):
return np.median(group.dropna())
ave = data.groupby('segment')['Metric'].apply(mymed)
It would be easier if you could provide some sample data which replicates the error.
Here is a different approach, you can add the median back to your original dataframe, the median for the metric column becomes:
data['metric_median'] = data.groupby('Segment')['Metric'].transform('median')
Wether its useful to have the median of the group attached to each datapoint depends a bit what you want to do afterwards.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…