초기 커밋
This commit is contained in:
26
app/processing/utils/dataframe_utils.py
Normal file
26
app/processing/utils/dataframe_utils.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
import polars as pl
|
||||
|
||||
|
||||
def filter_time_range(
|
||||
df: pl.DataFrame, column: str, start: datetime, end: datetime
|
||||
) -> pl.DataFrame:
|
||||
return df.filter(
|
||||
(pl.col(column) >= start) & (pl.col(column) <= end)
|
||||
)
|
||||
|
||||
|
||||
def resample(df: pl.DataFrame, time_column: str, interval: str) -> pl.DataFrame:
|
||||
numeric_cols = [
|
||||
c for c in df.columns if c != time_column and df[c].dtype.is_numeric()
|
||||
]
|
||||
return df.sort(time_column).group_by_dynamic(time_column, every=interval).agg(
|
||||
[pl.col(c).mean().alias(c) for c in numeric_cols]
|
||||
)
|
||||
|
||||
|
||||
def to_records(df: pl.DataFrame) -> list[dict]:
|
||||
return df.to_dicts()
|
||||
Reference in New Issue
Block a user