Styling DataFrames
Explore techniques for styling pandas DataFrames including formatting numeric and date columns, embedding bar plots in cells, highlighting key data points, adding heatmaps, and customizing appearance with CSS properties. Understand how to use sparklines for trend visualization, apply sticky headers, and hide index to improve data display in Jupyter notebooks.
Loading the data
Now that we have the basic data, we’re going to do some aggregations and column creation. Let’s see if we can go through the following code and figure out what it’s doing. We’ll go through the explanation right after showing it, but we recommend that after going through this course, you should start practicing reading code and ensuring that you understand what it’s doing.
There might have been a curveball in here—the sparklines library. Let’s skip that for now and describe the rest of the chain.
Group by the months in the index (note that we’re using named aggregations and that, as the comment states, the result of the resample method does not support named aggregations). For each group, calculate the median of the cfs column, calculate total_flow from the cfs column (it’s the 15-minute value, so we multiply it by 15 to get the minutes and 60 to get the seconds), and create a flow_trend column that uses sparklines.
After grouping, we’re going to make some more columns. The “quarterly_flow” column resamples our monthly data to the quarterly level and sums it. The “percent_quarterly_flow” column divides “total_flow” by “quarterly_flow.” ...