from_polars(df, items=None, datetime_col=None)
Create a Dataset from a polars DataFrame.
Parameters
df |
'pl.DataFrame' |
DataFrame |
required |
items |
Mapping[str, ItemInfo] | Sequence[ItemInfo] | ItemInfo | None |
Mapping of item names to ItemInfo objects, or a sequence of ItemInfo objects, or a single ItemInfo object. |
None |
datetime_col |
str | None |
Name of the column containing datetime information, default is to use the first datetime column found. |
None |
Returns
|
Dataset |
time series dataset |
Examples
import polars as pl
import mikeio
from datetime import datetime
df = pl.DataFrame(
{
"time": [datetime(2021, 1, 1), datetime(2021, 1, 2)],
"A": [1.0, 2.0],
"B": [4.0, 5.0],
}
)
ds = mikeio.from_polars(
df,
items={
"A": mikeio.ItemInfo(mikeio.EUMType.Water_Level),
"B": mikeio.ItemInfo(mikeio.EUMType.Discharge),
},
)
ds
<mikeio.Dataset>
dims: (time:2)
time: 2021-01-01 00:00:00 - 2021-01-02 00:00:00 (2 records)
geometry: GeometryUndefined()
items:
0: A <Water Level> (meter)
1: B <Discharge> (meter pow 3 per sec)