liveBook · Manning

Apply

As explained in Build Python Web Apps with Streamlit

The pandas apply method applies a function across dataframe rows, columns, groups, or Series values.

Use pandas apply to run a function across rows, columns, Series values, or groups. With grouped data, it processes each group separately, making it useful for turning detailed records into dashboard-ready summaries. section 6.5.1

Aggregate daily sales

Group records by Day, then sum Sales within each group: grouped = df.groupby('Day'); data = grouped.apply(lambda df: df['Sales'].sum(), include_groups=False).reset_index(). The function receives one day's rows, while include_groups=False prevents it from operating on the group label. reset_index() restores Day as a regular column. section 6.5.1

How Build Python Web Apps with Streamlit covers it

How deep it goes
Explains grouped execution, lambda aggregation, group-label exclusion, and index restoration, but not broader performance trade-offs.
Examples
Demonstrates summing daily Sales from state, gender, and product records for a Plotly time series.
What it assumes
Assumes familiarity with pandas DataFrames, columns, grouping, lambda functions, and indexes.
What you can do after
Builds grouped summary data and supplies it to a reusable time series chart.
How it connects
Connects apply with pandas DataFrame, Series, groupby, lambda functions, and reset_index.

Also explained in

Compare how 3 books explain apply →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Python Web Apps with Streamlit. The section links point to the parts of the book it draws on.