Skip to content

Feature request: Pandas input #8

@dean-sh

Description

@dean-sh

Hello,
Thank you for this!

Would be happy if I could input a pandas series with datetime64 format / datetime index and get the settlement period pandas series as an output. Perhaps there could be a more efficient way to handle a long time series other than running .apply to every row.

With the current implementation, such effect can be (inefficiently) achieved like so:

from sp2ts import ts2sp, to_unixtime

df["datetime"] = pd.to_datetime(
    df.index, utc=True
).tz_convert("Europe/London")

# Convert the datetime column to Unix time using a vectorized operation
unix_times = df["datetime"].apply(to_unixtime)

# Apply the ts2sp function to the entire Unix time series at once
dates, settlement_periods = zip(*unix_times.apply(ts2sp))

df["date"] = dates
df["sp"] = settlement_periods

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions