SShortSingh.
Back to feed

Pandas pct_change and resample: Handling Gaps in Time Series Data

0
·3 views

Data analyst Michael Nocito published a tutorial on August 8, 2026, explaining how to use pandas functions pct_change() and cumsum() to calculate period-on-period change and running totals from transactional data. A key finding highlighted is that pandas' groupby method only creates rows for periods with existing data, while resample automatically fills in missing calendar periods with zeros. Using a real 16-row orders dataset spanning January to May 2026, the guide demonstrates how a missing April causes groupby to return four rows instead of five, skewing percentage-change calculations. The tutorial also explains an edge case where pct_change() returns infinity when a value rises from zero, since division by zero has no finite result. Nocito recommends resample with a datetime index as the more reliable approach for building regular time series before applying any change or cumulative calculations.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

SRE Guide: How to Keep Databases Reliable With Backups, Pooling, and Monitoring

A site reliability engineering (SRE) post on DEV Community outlines practical techniques for maintaining database reliability in production environments. A key lesson shared is that untested backups are unreliable — the author discovered their backups had been silently failing for three weeks after an S3 bucket policy change, only realizing it during a data corruption incident. To prevent recurrence, the team built an automated weekly restore-test script that validates backup integrity against live production data, catching four backup issues over the past year. The article also covers reducing PostgreSQL connection overhead using PgBouncer in transaction mode, which can cut backend connections from hundreds down to around 25. Additional recommendations include monitoring replication lag, identifying slow queries via pg_stat_statements, performing zero-downtime schema migrations with concurrent indexing, and tracking key dashboard metrics such as cache hit ratio, query latency percentiles, and disk growth rate.

0
ProgrammingDEV Community ·

Open Source Relicensing Wave Backfires as Elastic and Redis Return to Open Licensing

Between 2018 and 2024, MongoDB, Elastic, HashiCorp, and Redis each moved away from open-source licenses after hyperscalers like AWS launched competing managed services built on their codebases. The relicensing moves drew community backlash, prompted forks like OpenTofu, and yielded no clear revenue gains for the companies involved. Elastic and Redis both reversed course within two years, restoring open-source licensing options, while HashiCorp — the only one that did not reverse — was acquired by IBM and ceased to exist as an independent company. The pattern suggests that restricting community rights to defend against cloud competition largely failed as a business strategy. Some newer database ventures, such as ZizkaDB, are responding by adopting AGPLv3 from the outset and pursuing enterprise deployment models that avoid dependence on a proprietary hosted layer.

0
ProgrammingDEV Community ·

Riverpod vs Bloc in 2026: Which Flutter State Management Tool Fits Your Team

A developer with production experience in both Riverpod and Bloc has published a detailed comparison of the two leading Flutter state management libraries. The analysis scores each library across seven criteria, including learning curve, boilerplate, async handling, testability, developer tools, team ergonomics, and ecosystem maturity. Riverpod scores higher for ease of learning and async state handling, while Bloc leads in testability, dev tooling, and scaling across large multi-developer teams. Neither library dominates every category, and the author argues the right choice depends on team size, project complexity, and tolerance for enforced structure. The piece concludes with a decision framework developers can apply to their own projects rather than a single universal recommendation.

0
ProgrammingDEV Community ·

Developer builds real-time Android screen translator using Compose, ML Kit, and Gemini

A developer has created an open-source Android app called ALSTMobile that translates on-screen text in real time without requiring manual screenshots or app switching. The tool addresses common friction points with existing screen translation methods, such as frozen screens and intrusive line-by-line OCR overlays. It uses Jetpack Compose, Google ML Kit, and Gemini Vision to capture frames via a virtual display and map translated text back onto the screen as spatial overlays. The project is released under the MIT License and its first stable version, v1.0.0, is available as an APK on GitHub.