Tick Bars Sampling

Data Preparation & Feature Engineering DS practice problem on Onlearn.

Difficulty: medium.

Topics: Understanding Financial Data Resampling Techniques, Cumulative Summation, Threshold-based Triggering, Data Resampling, Tick Data Processing, Groupby Aggregation, Time Series Analysis, Financial Econometrics, Data Preprocessing, Quantitative Finance, Statistical Sampling, Market Microstructure, Event-based Sampling, Data Aggregation, Feature Engineering, Information-driven Bars.

Implement a function 'get tick bars' that takes a pandas DataFrame of trades (containing a 'tick count' column) and an integer 'threshold'. The function should return a new DataFrame where each row represents a 'tick bar'—a sample formed by aggregating data once the cumulative number of ticks reaches the specified threshold. For non numeric columns, use the last value; for numeric columns, use the sum.