Skip to content
Advertisement

Tag: pandas-groupby

conditional groupby and update column – python, pandas, groupby

i have a df which I want to add a column that shows the student who is place (1) from the group(‘subject’, ‘class’) and update the column after there is a new place (1). code: ╔═════════╦═════════╦═════════╦═══════╗ ║ subject ║ class ║ student ║ place ║ ╠═════════╬═════════╬═════════╬═══════╣ ║ eng ║ Class_4 ║ henry ║ 7 ║ ║ math ║ Class_3 ║

Get Top N items per month in pandas

I have the following dataframe (which is a pretty reduced sample from my original one). I’m trying to get the top 2 ids for each year AND month. So, for example, the idea was to obtain the below df. My main problem here, is to get the Top n along with the dates, because the nlargest method applies to a

Plotting row based data

I have some data that looks something like this: What I would like to do is to plot the values of the header dates, but grouped by id and period. So essentially this would become 6 line plots, with the x-axis given as the dates. However, maybe I’m just tired, but this data set is weirdly put together imo, so

how to add new row into each group of groupby in PANDAS , one of the value of that row is sum of values of each groups

let’s say I have a data frame like this I wanted to add a new row into each group of groupby(by=[‘eff_date’,’mdl_cd’,’ast_cd’]) in which column value for eff_date,mdl_cd and ast_cd will remain same but for prop_cd value become Hlds and value value column become sum of value of that group e.g. for first group value of value column will be (-0.1234+0.5123+-0.7612)

Advertisement