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 -
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