Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

pandas add a value counts column to dataframe

df['Counts'] = df.groupby(['Color'])['Value'].transform('count')

# Go from this df
Color Value
Red   100
Red   150
Blue  50

# to this df
Color Value Counts
Red   100   2
Red   150   2 
Blue  50    1
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #pandas #add #counts #column #dataframe
ADD COMMENT
Topic
Name
4+1 =