What do you want to save?
Add Code snippet
New code examples
-
Python 2021-10-23 14:25:06
add a new categorical column to an existing table python
d = df.groupby('Item_Identifier')['Sales'].mean().to_dict() print (d) {'Beef': 3030.0, 'Milk': 1233.3333333333333, 'Tea': 150.0} print (df['Item_Identifier'].map(d)) 0 1233.333333 1 1233.333333 2 1233.333333 3 3030.000000 4 3030.000000 5 ... Add solution -
Other 2021-10-23 04:19:11
dax count distinct based on 2 columns
--Without filters Measure1 = COUNTROWS(GROUPBY(User,User[FNAME],User[Card ID],User[Health ID],User[Gender])) --With filters Measure2 = COUNTROWS(FILTER(GROUPBY(User,User[FNAME],User[Card ID],User[Health ID],User[Gender]),User[Gender]="M")) Add solution -
Python 2021-10-22 06:38:19
pandas condense dataframe by summing according to ID
# Original dataframe df: Fruit Date Name Number Apples 10/6/2016 Bob 7 Apples 10/6/2016 Bob 8 Apples 10/6/2016 Mike 9 Apples 10/7/2016 Steve 10 Apples 10/7/2016 Bob 1 Oranges 10/7/2016 Bob 2 Oranges 10/6/2016 Tom 15 Oranges 10... Add solution -
Python 2021-10-21 09:57:08
grouping products for sales
data = Item[Item['Bill No'].duplicated(keep=False)] # Referenced: https://stackoverflow.com/questions/27298178/concatenate-strings-from-several-rows-using-pandas-groupby data['Grouped'] = data.groupby('Bill No')['Item Name'].transform(lambda x: ','.join(... Add solution -
Python 2021-10-19 17:53:12
normalize a group in countplot
import numpy as np import pandas as pd import seaborn as sns sns.set(color_codes=True) df = sns.load_dataset('titanic') df.head() x,y = 'class', 'survived' (df .groupby(x)[y] .value_counts(normalize=True) .mul(100) .rename('percent') .reset_index() .pi... Add solution
Best helpers
Ranking is empty